代码输出有问题!求大佬!

P1219 [USACO1.5] 八皇后 Checker Challenge

我感觉你的dfs有问题
by czx6666 @ 2024-02-25 14:43:16


具体是哪里有问题呢?
by Wangyuqi2010 @ 2024-02-25 15:01:32


@[czx6666](/user/1056023)
by Wangyuqi2010 @ 2024-02-25 15:04:16


``` #include<bits/stdc++.h> using namespace std; int m1[30],m2[30],m3[30],ans[15],mark; int n; void state(int i,int j,int k){//问题 在这 ans[i]=j; m1[j]=k; cout<<1<<endl;//这里没有输出 m2[i+j]=k; m3[i-j+n]=k; } void dfs(int step) { if(step>n){ mark++; if(mark<=3){ for(int l=1;l<=n;l++){//这里也没有输出 cout<<ans[l]<<' '; } cout<<endl; } cout<<1;//只输出了一个 return ;//这里不能有else } for(int j=1;j<=n;j++){ if(m1[j]||m2[step+j]||m3[step-j+n]) continue; state(step,j,1); dfs(step+1); state(step,j,0); } } int main() { int n; cin>>n; dfs(1); cout<<mark; return 0; } ```
by czx6666 @ 2024-02-25 15:10:33


@[Wangyuqi2010](/user/1016748)
by czx6666 @ 2024-02-25 15:12:22


okk 谢谢大佬 @[czx6666](/user/1056023)
by Wangyuqi2010 @ 2024-02-25 15:41:05


|