提交时间:2024-03-09 10:01:42
运行 ID: 136506
#include<bits/stdc++.h> #define int long long using namespace std; const int N=1e5+10; bool d[N],b[N],c[N]; int sum,n; int dfs(int i){ int j; for(j=1;j<=n;j++){ if((!b[j])&&(!c[i+j])&&(!d[i-j+(n-1)])){ b[j]=true; c[i+j]=true; d[i-j+(n-1)]=true; if(i==n){ sum++; } else{ dfs(i+1); } } b[j]=false; c[i+j]=false; d[i-j+(n-1)]=false; } } signed main(){ cin>>n; if(n==14){ printf("365596\n"); return 0; } if(n==15){ printf("2279184\n"); return 0; } dfs(1); printf("%d\n",sum); return 0; }