-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshunxudui.cpp
More file actions
60 lines (51 loc) · 1.1 KB
/
shunxudui.cpp
File metadata and controls
60 lines (51 loc) · 1.1 KB
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
#include <iostream>
#include <algorithm>
#include <memory.h>
using namespace std;
const int N = 100;
int a[N], b[N], visit[N];
int c[15];
int judge(int n, int k, int b[])
{
int res = 0;
for (int i = 1; i <= n; i++)
for (int j = i+1; j <= n; j++)
if (b[i] < b[j])
res++;
return res == k;
}
int main()
{
int n, k;
cin >> n >> k;
int ans = 0;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
visit[a[i]] = 1;
}
int total = 0;
for (int i = 1; i <= n; i++ )
{
if (visit[i] == 0)
c[total++] = i;
}
int index[15] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
do {
int idx = 0;
for (int i = 1; i <= n; i++)
{
if (a[i] == 0) {
b[i] = c[index[idx++]];
} else {
b[i] = a[i];
}
}
if (judge(n, k, b))
ans++;
for (int i = 0; i <= n; i++)
cout << index[i];
cout << endl;
} while (next_permutation(index, index+total));
cout << ans;
}