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; char s[9][9]; int flag[9][9]; bool hang[9],lie[9]; int n,k,sum; void dfs(int a,int b,int k) { if(k==0) { sum++; return ; } if(n-a<k) return ; if(b>=n) dfs(a+1,0,k); else if(a>=n) return ; else { if(flag[a][b]==0&&hang[a]==false&&lie[b]==false) { hang[a]=true; lie[b]=true; dfs(a+1,0,k-1); hang[a]=false; lie[b]=false; } dfs(a,b+1,k); } } int main() { while(scanf("%d%d",&n,&k)!=EOF) { memset(hang,0,sizeof(hang)); memset(lie,0,sizeof(lie)); sum=0; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { cin>>s[i][j]; if(s[i][j]=='#') flag[i][j]=0; else if(s[i][j]=='.') flag[i][j]=1; } } if(k==0) printf("0\n"); else { dfs(0,0,k); printf("%d\n",sum); } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator