mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-27 14:36:27 +00:00
P1219 [USACO1.5]八皇后 Checker Challenge
R41967120
This commit is contained in:
parent
782ac0d882
commit
6f245e923d
33
problem/P1219/P1219.cpp
Normal file
33
problem/P1219/P1219.cpp
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user