回溯算法理论基础
class Solution { public: vector<vector<int>> result; vector<int> path; void dfs(int n, int k, int start){ if(path.size() == k){ result.push_back(path); return; } for(int i=start; i<=n; i++){ path.push_back(i); dfs(n, k, i+1); path.pop_back(); } } vector<vector<int>> combine(int n, int k) { dfs(n, k, 1); return result; } };
标签:part01,day24,int,算法,result,回溯,path From: https://www.cnblogs.com/zqh2023/p/17685323.html