weiyi8910 @ 2025-01-11 08:58:07
#include <bits/stdc++.h>
using namespace std;
long long id = 0, a[100], b[100], c[100][2], n, s = 0;
void dfs(int i) {
if (id < 3 && i > n) {
for (long long i = 1; i <= s; i++) {
cout << a[i] << ' ';
}
cout << endl;
id++;
return ;
} else if (i > n) {
id++;
} else {
for (long long j = 1; j <= n; j++) {
if (!c[i - j + n][1] && !c[i + j][0] && !b[j]) {
s++;
a[s] = j;
b[j] = 1;
c[i - j + n][1] = 1;
c[i + j][0] = 1;
dfs(i + 1);
b[j] = 0;
c[i - j + n][1] = 0;
c[i + j][0] = 0;
s--;
}
}
}
}
int main() {
cin >> n;
dfs(1);
cout << id;
return 0;
}
by weiyi8910 @ 2025-01-11 09:00:59
哦,偏移会出数组,那为什么不是RE