-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproperties.cpp
More file actions
65 lines (58 loc) · 1.31 KB
/
properties.cpp
File metadata and controls
65 lines (58 loc) · 1.31 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
60
61
62
63
64
65
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int n;
int method;
bool checkAntimonotonic(int array[], int n) {
for (int i = 1; i < n-1; ++i) {
if (array[i] > array[i-1] && array[i] > array[i+1]) {
continue;
}
else if (array[i] < array[i-1] && array[i] < array[i+1]) {
continue;
}
else return false;
}
return true;
}
bool checkCyclic(int array[], int n) {
int ptr = array[0];
int count = 0;
while (ptr != 0) {
ptr = array[ptr];
++count;
}
if (count == n-1) {
return true;
}
else return false;
}
void permute(bool isUse[], int array[], int index) {
if (index == n) {
if (checkCyclic(array, n)) {
if (checkAntimonotonic(array, n)) {
++method;
}
}
return;
}
for (int i = 0; i < n; ++i) {
if (isUse[i] == false) {
if (i != index) {
isUse[i] = true;
array[index] = i;
permute(isUse, array, index+1);
isUse[i] = false;
}
}
}
}
int main() {
scanf("%d",&n);
method = 0;
bool *isUse = (bool *)calloc(sizeof(bool), n);
int array[n];
permute(isUse, array, 0);
printf("%d",method);
}