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 |
求测试数据!!!好郁闷,一直WAWAWAWAWA代码 : #include<stdio.h> static int data[21][21]; int dcount; int maxresult=0; void dfs(int curr,int curc,int count) { int i,j,flag; if(curr>dcount) { if(maxresult<count) maxresult=count; return; } flag=0; if(data[curr][curc]==0)//当前是空地 { flag=1; //上边 for(j=curr-1;j>0;j--) if(data[j][curc]==1)//1表示已经放了东西 { flag=0; break; } else if(data[j][curc]==2) { break; } //左边 for(j=curc-1;j>0;j--) if(data[curr][j]==1)//1表示已经放了东西 { flag=0; break; } else if(data[curr][j]==2) { break; } } if(flag==1)//放 { data[curr][curc]=1; if(curc<dcount) dfs(curr,curc+1,count+1); else dfs(curr+1,1,count+1); data[curr][curc]=0; } //不放 if(curc<dcount) dfs(curr,curc+1,count); else dfs(curr+1,1,count); } int main() { int i,j; char tempc; while(scanf("%d",&dcount)!=EOF) { maxresult=0; if(dcount==0) return 0; //dcount==dcount for(i=1;i<=dcount;i++) { fflush(stdin); for(j=1;j<=dcount;j++) { tempc=getchar(); if(tempc=='.') data[i][j]=0; else data[i][j]=2; } } dfs(1,1,0); printf("%d\n",maxresult); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator