Yukimiku @ 2023-09-04 19:10:08
#include<bits/stdc++.h>
using namespace std;
int n,a[1100],ans,b1[1000],b2[1000],b3[1000];
void dfs(int x)
{
if(x>n){
ans++;
if(ans<=3){
for(int i=1;i<=n;i++) cout<<a[i]<<" ";
cout<<endl;
}
return;}
for(int i=1;i<=n;i++){
if(b1[i]==0&&b2[x+i]==0&&b3[x-i+n]==0)
{
a[x]=i;
b1[i]==1;b2[x+i]==1;b3[x-i+n]==1;
dfs(x+1);
b1[i]==0;b2[x+i]==0;b3[x-i+n]==0;}
}
}
int main()
{
scanf("%d",&n);
dfs(1);
printf("%d",ans);
return 0;
}
by DaShaber @ 2023-09-04 19:12:07
b1[i]==1;b2[x+i]==1;b3[x-i+n]==1;
?
by Yukimiku @ 2023-09-04 19:12:54
@caibyte 我去看到了wssb
by Yukimiku @ 2023-09-04 19:14:03
@caibyte 感谢了,应该是我眼睛瞎,当给大家看乐子罢(悲
by DaShaber @ 2023-09-04 19:16:51
复制的时候忘记检查了吧
这种问题广泛存在于大部分 OIer 的各种代码里捏