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 i,j,ans,n,row,col; char ch; char value[5][5]; bool ok(int row,int col) { for(i=row-1;i>=0;i--) { if(value[i][col]=='o') return false; if(value[i][col]=='X') break; } for(j=col-1;j>=0;j--) { if(value[row][j]=='o') return false; if(value[col][j]=='X') break; } return true; } void search(int x,int y) { if(x==n*n) { if(y>ans) ans=y; return ; } else { row=x/n; col=x%n; if(value[row][col]=='.'&&ok(row,col)) { value[row][col]='o'; search(x+1,y+1); value[row][col]='.'; } search(x+1,y); } } int main() { while(cin>>n) { if(n==0) break; for(i=0;i<n;i++) for(j=0;j<n;j++) { cin>>value[i][j]; } ans=0; search(0,0);//第一个参数表示从第几个位置,第二个参数表示的是放了几个城堡 cout<<ans<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator