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 <stdio.h> #include <algorithm> char a[10][10]; int vis[9]; //为0时则没走过 为1时 表示走过 int m; void dfs(int k,int n,int t,int nm); int main() { int n,k,i,j,t; while(scanf("%d%d",&n,&k)!=EOF) { if(n==-1&&k==-1) return 0; getchar(); for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { scanf("%c",&a[i][j]); getchar(); } } memset(vis,0,9*sizeof(int)); t=1; m=0; dfs(k,n,t,1); printf("%d\n",m); } } void dfs(int k,int n,int t,int nm) { int i,j; if(t==k+1) //t代表的是该搜索的第t个数 { m++; return ; } else { for(i=nm;i<=n;i++) //nm表示行数 { for(j=1;j<=n;j++) { if(a[i][j]=='#'&&vis[j]!=1) { vis[j]=1; dfs(k,n,t+1,i+1); vis[j]=0; } } } return ; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator