Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- vector < vector <int> > ans;
- int mark[20 + 10];
- int N, K;
- void f(int k, int prev){
- if(k == K){
- vector <int> cur;
- for(int i=1;i<=N;i++)
- if(mark[i]) cur.push_back(i);
- ans.push_back(cur);
- }
- for(int i=prev+1;i<=N;i++){
- if(!mark[i]){
- mark[i] = true;
- f(k + 1, i);
- mark[i] = false;
- }
- }
- }
- vector<vector<int>> combine(int n, int k) {
- N = n, K = k;
- f(0, 0);
- return ans;
- }
- };
Add Comment
Please, Sign In to add comment