0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-03 19:16:27 +00:00

#593. 八皇后问题

https://sjzezoj.com/submission/44617
This commit is contained in:
Baoshuo Ren 2021-11-17 21:28:20 +08:00 committed by Baoshuo Ren
parent aa5aacbd36
commit f3aba05aeb
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

34
S2OJ/593/593.cpp Normal file
View File

@ -0,0 +1,34 @@
#include <bits/stdc++.h>
using namespace std;
int n, ans, a[105];
bool col[105], dg[105], udg[105];
void dfs(int i) {
if (i > n) {
if (ans < 3) {
for (int i = 1; i < n; i++) {
cout << a[i] << ' ';
}
cout << a[n] << endl;
}
ans++;
return;
}
for (int j = 1; j <= n; j++) {
if (!col[j] && !dg[i + j] && !udg[n - j + i]) {
a[i] = j;
col[j] = dg[i + j] = udg[n - j + i] = true;
dfs(i + 1);
col[j] = dg[i + j] = udg[n - j + i] = false;
}
}
}
int main() {
cin >> n;
dfs(1);
cout << ans << endl;
return 0;
}