Description
Input
Output
Sample Input
2 1 #. .# 4 4 ...# ..#. .#.. #... -1 -1
Sample Output
2 1
Source
#include<cstring> #include<cstdio> #include<algorithm> #include<iostream> using namespace std; int n,k,ans; bool map[10]; bool mark[10][10]; void dfs(int col ,int m) { if(m == k){ ans++; return; } if(col > n) return ; for(int j = 1; j <= n ;j++){ if(mark[col][j] == true && map[j] == false){ map[j] = true; dfs(col+1,m+1); map[j] = false; } } dfs(col+1,m); return ; } int main() { char temp; while(cin >> n >> k){ if(n == -1 && k == -1) break; ans = 0; memset(mark,false,sizeof(mark)); memset(map,false,sizeof(map)); for(int i = 1; i <= n ;i++){ for(int j = 1; j <= n ;j++){ cin >> temp; if(temp == ‘#‘) mark[i][j] = true; } } dfs(1,0); printf("%d\n",ans); } return 0; }
原文:http://www.cnblogs.com/zero-begin/p/4363694.html