-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path77.cpp
More file actions
executable file
·33 lines (33 loc) · 758 Bytes
/
77.cpp
File metadata and controls
executable file
·33 lines (33 loc) · 758 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include<iostream>
#include<vector>
#include <unordered_map>
using namespace std;
class Solution {
public:
int mxn;
int mxk;
unordered_map<int, int> count;
vector<int> tmp;
vector<vector <int> > answer;
void dfs(int cur, int last){
if (cur == mxk + 1){
answer.push_back(tmp);
return;
}
for (int i = last+1; i < mxn+1; i++){
if (count[i] == 0){
tmp.push_back(i);
count[i] = 1;
dfs(cur+1,i);
tmp.pop_back();
count[i] = 0;
}
}
}
vector<vector<int> > combine(int n, int k) {
mxn = n;
mxk = k;
dfs(1,0);
return answer;
}
};