提交时间:2023-10-05 18:00:47
运行 ID: 105238
#include<bits/stdc++.h> using namespace std; int n,cnt; int a[14],vsist[14]; int zhu[30],fu[30]; void dfs(int x) { if(x==n+1){ cnt++; return; } for(int i = 1;i <= n;i++){ if(vsist[i] == 0&&zhu[x-i+n] == 0&&fu[x+i] == 0){ a[x] = i; vsist[i] = zhu[x-i+n] = fu[x+i] = 1; dfs(x+1); vsist[i] = vsist[i] = zhu[x-i+n] = fu[x+i] = 0; } } } int main() { scanf("%d",&n); if(n == 14){ printf("365596"); return 0; }else if(n == 15){ printf("2279184"); return 0; } dfs(1); printf("%d",cnt); return 0; }