-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path15648.cpp
More file actions
45 lines (34 loc) · 711 Bytes
/
Copy path15648.cpp
File metadata and controls
45 lines (34 loc) · 711 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
34
35
36
37
38
39
40
41
42
43
44
45
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
bool isUsed[9] = {};
int seq[8] = {};
int N, M;
void printSeq(int lv){
if(lv==M){
for(int i=0; i<M; i++) cout << seq[i] << ' ';
cout << '\n';
return;
}
for(int i=1; i<=N; i++){
if(isUsed[i]) continue;
seq[lv] = i;
isUsed[i] = true;
printSeq(lv+1);
isUsed[i] = false;
}
}
int main(){
cin.tie(NULL);
ios_base::sync_with_stdio();
cin >> N >> M;
for(int i=1; i<=N; i++){
for(int i=1; i<=N; i++){
isUsed[i] = false;
}
seq[0] = i;
isUsed[i] = true;
printSeq(1);
}
}