87pts WA最后一个点aaa

P1219 [USACO1.5] 八皇后 Checker Challenge

用 `dfs` 怎么错了???
by peterJr @ 2024-03-27 19:40:35


@[peterJr](/user/1050776) ``` #include<bits/stdc++.h> using namespace std; int n; bool v[15]; int a[15]; bool b[30],c[30]; int ans=0; void dfs(int x) { if (x>n) { ans++; if (ans<=3) { for (int i=1;i<=n;i++) cout<<a[i]<<" "; cout<<endl; } } else { for (int i=1;i<=n;i++) { if (v[i] && b[i+x] && c[i-x+n]) { a[x]=i; v[i]=false; b[i+x]=false; c[i-x+n]=false; dfs(x+1); v[i]=true; b[i+x]=true; c[i-x+n]=true; } } } } int main() { cin>>n; memset(v,true,sizeof(v)); memset(a,0,sizeof(a)); memset(b,true,sizeof(b)); memset(c,true,sizeof(c)); dfs(1); cout<<ans; return 0; } ```
by jydz @ 2024-04-08 13:29:32


|