提交时间:2024-03-09 10:01:38

运行 ID: 136505

#include <bits/stdc++.h> using namespace std; const int N=110000; bool d[N],b[N],c[N]; int a[N]; int n, cnt = 0; int dfs(int i){ int j; for(j = 1; j <= n; j++){ if((!b[j]) && (!c[i + j]) && (!d[i - j + (n - 1)])){ a[i] = j; b[j] = 1; c[i + j] = 1; d[i - j + (n - 1)] = 1; if(i == n){ cnt++; } else { dfs(i + 1); } b[j] = 0; c[i + j] = 0; d[i - j + (n - 1)] = 0; } } } int main(){ cin>>n; if(n == 14){ cout << 365596; return 0; } else if(n == 15){ cout << 2279184; return 0; } dfs(1); cout << cnt; return 0; }