标签:
2 1 #. .# 4 4 ...# ..#. .#.. #... -1 -1
2 1
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <cstdlib> 6 #include <algorithm> 7 #include <stack> 8 #include <set> 9 #include <map> 10 #include <queue> 11 #include <ctime> 12 #define LL long long 13 #define INF 0x3f3f3f3f 14 #define pii pair<int,int> 15 16 using namespace std; 17 const int maxn = 10; 18 char table[maxn][maxn]; 19 int n,k,sum; 20 bool vis[maxn]; 21 void dfs(int cur,int cnt){ 22 if(cnt == k){ 23 ++sum; 24 return; 25 } 26 if(cur >= n || n-cur < k-cnt) return; 27 for(int i = 0; i < n; ++i){ 28 if(vis[i]||table[cur][i] == ‘.‘) continue; 29 vis[i] = true; 30 dfs(cur+1,cnt+1); 31 vis[i] = false; 32 } 33 dfs(cur+1,cnt); 34 } 35 int main(){ 36 while(scanf("%d %d",&n,&k),~n || ~k){ 37 memset(table,‘\0‘,sizeof(table)); 38 memset(vis,false,sizeof(vis)); 39 for(int i = sum = 0; i < n; ++i) 40 scanf("%s",table[i]); 41 dfs(0,0); 42 printf("%d\n",sum); 43 } 44 return 0; 45 }
标签:
原文地址:http://www.cnblogs.com/crackpotisback/p/4236092.html