Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
136505 | 罗嘉为 | N皇后问题 | C++ | 通过 | 100 | 325 MS | 276 KB | 616 | 2024-03-09 10:01:38 |
#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; }