#include
#include
#include
#include
const int maxn = 10;
int n;
int P[maxn], hashTable[maxn] = { false };
int count = 0;
int generateP(int index){
if (index == n + 1){
bool flag = true;
for (int i = 1; i <= n; i++){
for (int j = i + 1; j <= n; j++){
if (abs(i - j) == abs(P[i] - P[j])){
flag = false;
}
}
}
if (flag) count++;
return count ;
}
for (int x = 1; x <= n; x++){
if (hashTable[x] == false)
P[index] = x;
hashTable[x] = true;
generateP(index + 1);
hashTable[x] = false;
}
}
int main(){
scanf_s("%d", &n);
generateP(1);
printf("%d", count);
system("pause");
return 0;
}
运行不输出结果,有没有大佬知道为什么