#include <bits/stdc++.h> using namespace std; bool f1[10],f2[10],f3[10]; int a[10][10]; int ans; void dfs(int x){ if(x == 9){ ans++; cout<<"No. "<<ans<<endl; for(int i = 1;i <= 8;i++){ for(int j = 1;j <= 8;j++){ cout<<a[j][i]<<" "; } cout<<endl; } return; } for(int j = 1;j <= 8;j++){ if(!f1[j] && !f2[x + j] && !f3[x - j + 8]){ f1[j] = f2[x + j] = f3[x - j + 8] = true; a[x][j] = 1; dfs(x + 1); f1[j] = f2[x + j] = f3[x - j + 8] = false; a[x][j] = 0; } } } int main(){ dfs(1); return 0; }

0 条评论

目前还没有评论...

信息

ID
215
时间
ms
内存
MiB
难度
3
标签
递交数
175
已通过
46
上传者