-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10974.cpp
62 lines (50 loc) · 1.04 KB
/
10974.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
54
55
56
57
58
59
60
61
62
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int N;
cin >> N;
vector<int> v;
for(int i = 1; i <= N; i++)
v.push_back(i);
do{
for(auto elem : v){
cout << elem << ' ';
}
cout << '\n';
} while (next_permutation(v.begin(), v.end()));
}
/*
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int N;
int visited[8+1] = {false, };
bool flag = false;
void dfs(int cnt, vector<int> v){
if(cnt == N){
for(int i = 0; i < cnt; i++){
cout << v[i] << ' ';
}
cout << '\n';
return;
}
for(int i = 1; i <= N; i++){
if(!visited[i]){
visited[i] = true;
v[cnt] = i;
dfs(cnt+1, v);
visited[i] = false;
}
}
}
int main(){
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cin >> N;
vector<int> v(N);
dfs(0, v);
}
*/