mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-03 19:16:27 +00:00
parent
aa5aacbd36
commit
f3aba05aeb
34
S2OJ/593/593.cpp
Normal file
34
S2OJ/593/593.cpp
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user