0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-11 07:26:25 +00:00
OI-codes/Luogu/problem/P1219/P1219.cpp
2021-01-02 15:30:52 +08:00

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;
}