Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 22144 | Accepted: 10988 |
Description
Input
Output
Sample Input
2 1 #. .# 4 4 ...# ..#. .#.. #... -1 -1
Sample Output
2 1
#include<iostream> #include<cstring> using namespace std; int n,m,ans; int v[10]; char c[10][10]; void dfs(int r,int k) { int i,j; if(k==m) ans++; else for(i=r+1;i<n;i++) for(j=0;j<n;j++) if(c[i][j]=='#'&&!v[j]) { v[j]=1; dfs(i,k+1); v[j]=0; } } int main() { while(cin>>n>>m) { memset(v,0,sizeof(v)); if(n==-1&&m==-1) break; int i; for(i=0;i<n;i++) scanf("%s",c[i]); ans=0; dfs(-1,0); cout<<ans<<endl; } return 0; }
原文地址:http://blog.csdn.net/hyccfy/article/details/37956603