#include <bits/stdc++.h>
using namespace std;
bool f[15][15], shu[15], r_xie[20], l_xie[20], t = 0;
long long n, sum;
void print() {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (f[i][j]) cout << j + 1 << ' ';
}
}
cout << "\n";
}
void dfs(int x) {
if (x > n) {
sum ++;
if (sum > 3) {
t = 1;
return;
}
print();
return ;
}
for (int i = 0; i < n; i++) {
if (!shu[i] && !r_xie[x - i] && !l_xie[x + i]) {
shu[i] = 1;
r_xie[x - i] = 1;
l_xie[x + i] = 1;
f[x - 1][i] = 1;
dfs(x + 1);
f[x - 1][i] = 0;
shu[i] = 0;
r_xie[x - i] = 0;
l_xie[x + i] = 0;
}
}
}
int main() {
cin >> n;
dfs(1);
cout << sum;
return 0;
}
请大佬帮忙指一下错!谢谢!