0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-27 13:56:26 +00:00

P1219 [USACO1.5]八皇后 Checker Challenge

R41967120
This commit is contained in:
Baoshuo Ren 2020-11-15 20:14:38 +08:00 committed by Baoshuo Ren
parent 782ac0d882
commit 6f245e923d
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

33
problem/P1219/P1219.cpp Normal file
View File

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