提交时间:2023-10-14 10:25:45
运行 ID: 106717
#include<bits/stdc++.h> using namespace std; int n,cnt; int a[16],vsist[16]; 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() { dfs(1); printf("%d",cnt); return 0; }