AC了
2025-07-16 18:51:53
发布于:四川
2阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
int a[10];
bool b[10], c[20], d[20];
void func(int i) {
if (i > 8) {
for (int k = 1; k <= 8; k++) cout << a[k];
cout << endl;
return;
}
for (int j = 1; j <= 8; j++) {
if (!b[j] && !c[i+j] && !d[i-j+7]) {
a[i] = j;
b[j] = 1;
c[i+j] = 1;
d[i-j+7] = 1;
func(i+1);
b[j] = 0;
c[i+j] = 0;
d[i-j+7] = 0;
}
}
}
int main() {
func(1);
return 0;
}
这里空空如也
有帮助,赞一个