模板:

回溯模板

 1class Solution
 2{
 3private:
 4    vector<Type_> res;
 5    Type_ path;
 6public:
 7    void backtracking(输入参数)
 8    {
 9        if (终止条件)
10        {
11            res.push_back(path);
12            return;
13        }
14
15        for (本层要使用的集合)
16        {
17            处理节点;
18            backtracking(...);
19            回溯,即撤销之前的结果;
20        }
21    }
22
23    vector<Type_> func(输入参数)
24    {
25        backtracking(...);
26        return res;
27    }
28};

原文:回溯