-
Notifications
You must be signed in to change notification settings - Fork 8
/
1294.cpp
54 lines (45 loc) · 982 Bytes
/
1294.cpp
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <cassert>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <set>
#include <algorithm>
using namespace std;
void dfs(int n, vector<int> &cur, vector<vector<int> > &res, bool f[]) {
if(cur.size()>=n) {
res.push_back(cur);
return;
}
for(int i=0; i<n; i++) {
if(f[i]) {
f[i]=false;
cur.push_back(i+1);
dfs(n, cur, res, f);
cur.pop_back();
f[i]=true;
}
}
}
int main() {
int n;
cin >> n;
vector<int> cur;
vector<vector<int> > res;
bool *f=new bool[n];
for(int i=0; i<n; i++) {
f[i]=true;
}
dfs(n, cur, res, f);
for(int i=0; i<res.size(); i++) {
for(int j=0; j<res[i].size(); j++) {
cout << res[i][j];
if(j+1<res[i].size())
cout << " ";
}
if(i+1<res.size())
cout << endl;
}
return 0;
}