Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
为什么搜索总是wa阿?谁帮忙看下#include <iostream> using namespace std; int num[15]; int map[15][15]; int cc[15]; int n,ff; bool judge() { for(int i=0;i<n;i++) { if(cc[i]!=num[i])return 0; } return 1; } void dfs(int x,int y) { if(judge()) { ff=1; } if(y>=n)return ; if(ff==0) { if(map[x][y]==0&&cc[x]<num[x]&&cc[y]<num[y]) { cc[x]++; cc[y]++; map[x][y]=1; map[y][x]=1; } y++; if(y>=n){x++;y=x+1;} if(x>=n)return ; dfs(x,y); } if(ff==0) { if(map[x][y]==1) { cc[x]--; cc[y]--; map[x][y]=0; map[y][x]=0; } } return ; } int main () { int T; scanf("%d",&T); while(T--) { scanf("%d",&n); for(int i=0;i<n;i++)scanf("%d",num+i); memset(map,0,sizeof(map)); memset(cc,0,sizeof(cc)); ff=0; dfs(0,1); if(ff==0)printf("NO\n\n"); else { printf("YES\n"); for(int i=0;i<n;i++) { for(int j=0;j<n;j++)printf("%d ",map[i][j]); printf("\n"); } printf("\n"); } } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator