mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-27 20:56:37 +00:00
34 lines
664 B
C++
34 lines
664 B
C++
|
#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;
|
||
|
}
|