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 |
DFS AC代码#include<iostream> #include<cstring> #include<algorithm> using namespace std; char chess[10][10]; int col[10]; int n,m,ans; void dfs(int row,int num) { int i,j; if(num==m) { ans++; return; } for(i=row+1;i<=n;i++) for(j=1;j<=n;j++) if(chess[i][j]!='.' && !col[j]) { col[j]=1; dfs(i,num+1); col[j]=0; } } int main() { int i; while(cin>>n>>m) { ans=0; if(n==-1 && m==-1)break; memset(col,0,sizeof(col)); for(i=1;i<=n;i++) cin>>chess[i]+1; dfs(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