标签:
Description
Input
Output
Sample Input
2 1 #. .# 4 4 ...# ..#. .#.. #... -1 -1
Sample Output
2 1
#include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> #include<iostream> #include<algorithm> #include<vector> #include<map> #include<queue> #include<stack> #include<string> #include<map> #include<set> #include<ctime> #define eps 1e-6 #define LL long long #define pii pair<string, int> #define rd(x) scanf("%d",&x) #define rd2(x,y) scanf("%d%d",&x,&y) using namespace std; char mmap[10][10]; bool vis[10]; int n,k; int dfs(int row,int coun){ //cout<<row<<' '<<coun<<"**********"<<endl; int sum=0; if(coun == k) return 1; if(row < n){ for(int i=0;i<n;i++){ if(vis[i]==false&&mmap[row][i] == '#'){ vis[i] = true; sum+=dfs(row+1,coun+1); vis[i] = false; } } sum+=dfs(row+1,coun); } return sum; } int main (){ while(~rd2(n,k)&&n!=-1&&k!=-1){ memset(vis,0,sizeof(vis)); for(int i=0;i<n;i++){ scanf("%s",mmap[i]); } printf("%d\n",dfs(0,0)); } return 0; }
标签:
原文地址:http://blog.csdn.net/u014665013/article/details/51328829