-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhigh.cpp
58 lines (53 loc) · 1.25 KB
/
high.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
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int n,p,r;
int method;
void permute(bool isUse[], int array[], int index) {
if (index == n) {
int max = -1;
int leftSee = 0;
for (int i = 0; i < n; ++i) {
if (array[i] > max) {
++leftSee;
max = array[i];
}
}
if (leftSee != p) {
return;
}
max = -1;
int rightSee = 0;
for (int i = n-1; i >= 0; --i) {
if (array[i] > max) {
++rightSee;
max = array[i];
}
}
if (leftSee == p && rightSee == r) {
/*for (int i = 0; i < n; ++i) {
printf("%d ",array[i]);
}
printf("\n");*/
++method;
}
else return;
}
for (int i = 0; i < n; ++i) {
if (isUse[i] == false) {
isUse[i] = true;
array[index] = i;
permute(isUse, array, index+1);
isUse[i] = false;
}
}
}
int main() {
scanf("%d %d %d",&n,&p,&r);
method = 0;
bool *isUse = (bool *)calloc(sizeof(bool), n);
int array[n];
permute(isUse, array, 0);
printf("%d",method);
}