-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP1088 火星人.cpp
66 lines (66 loc) · 1.31 KB
/
P1088 火星人.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
63
64
65
66
#include<iostream>
#include<cstring>
using namespace std;
const int maxn = 10010;
int now[maxn], num[maxn];
bool vis[maxn], OK, readyToKill;
int n, m;long long cnt;
bool check() {
// bool flag = true;
for(int i=1; i<=n; i++) {
if(num[i]!=now[i])
return false;
}
return true;
}
void printAns() {
for(int i=1; i<n; i++) {
cout<<now[i]<<" ";
}
cout<<now[n]<<endl;
}
void getP(int cur) {
if(readyToKill) return;
if(cur>n) {
if(!OK) {
if(check()) {
OK = true;
/* if(m==1) {
cnt--;
}
else if(m==0) {
printAns();
readyToKill = true;
return;
}*/
}
}
else {
if(++cnt == m) {
printAns();
readyToKill = true;
}
}
}
else {
for(int i=1; i<=n; i++) {
if(!vis[i]) {
vis[i] = true;
now[cur] = i;
getP(cur + 1);
vis[i] = false;
}
}
}
}
int main() {
memset(vis, 0, sizeof vis);
cin>>n>>m;
int i;
for(i=1; i<=n; i++) {
cin>>num[i];
now[i] = 0;
}
getP(1);
return 0;
}