Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
136793 | 曾煦翔 | N皇后问题 | C++ | 运行超时 | 80 | 1000 MS | 248 KB | 466 | 2024-03-09 15:13:13 |
#include <bits/stdc++.h> using namespace std; const int N = 25; bool col[N] , zhu[N] , fu[N]; int ans; int n; void dfs(int x) { if(x == n + 1) { ans++; return; } for(int i = 1;i <= n;i++) { if(!col[i] && !zhu[x + i - 1] && !fu[x - i + n]) { col[i] = zhu[x + i - 1] = fu[x - i + n ] = 1; dfs(x + 1); col[i] = zhu[x + i - 1] = fu[x - i + n] = 0; } } } int main() { cin >> n; dfs(1); cout << ans; return 0; }