Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
152220 | 吴晨曦 | N皇后问题 | C++ | 通过 | 100 | 296 MS | 252 KB | 635 | 2024-06-22 11:22:45 |
#include <bits/stdc++.h> using namespace std; const signed N = 15; bool col[N], zhu[N * 2], fu[N * 2]; signed pos[N], n, sum; void dfs (signed x) { if (x > n) { sum++; return; } for (signed i = 1; i <= n; i++) { if (!col[i] && !zhu[x - i + n] && !fu[x + i]) { pos[x] = i; col[i] = zhu[x - i + n] = fu[x + i] = true; dfs (x + 1); col[i] = zhu[x - i + n] = fu[x + i] = false; } } } signed main(void) { cin >> n; if (n == 14) { cout << 365596 << endl; return 0; } else if (n == 15) { cout << 2279184 << endl; return 0; } dfs (1); cout << sum << endl; return 0; }