題目大意:ios
http://poj.org/problem?id=1321編程
Description測試
Inputspa
Outputcode
Sample Inputblog
2 1 #. .# 4 4 ...# ..#. .#.. #... -1 -1
Sample Outputip
2 1
代碼:
#include <iostream> using namespace std; char arr[10][10]; int flag[10]; int n,k,count; void dfs(int x, int num) { if(num == k) { count++; return; } if(x >= n) return ; for(int j = 0; j < n; j++) { if(arr[x][j] == '#' && !flag[j]) { flag[j] = true; dfs(x+1,num+1); flag[j] = false; } } dfs(x+1,num); return; } int main() { while(cin >> n >> k && !(n==-1 && k == -1)) { count = 0; for(int i = 0; i < n; i++) { flag[i] = 0; for(int j = 0 ;j < n; j++) { cin >> arr[i][j]; } } dfs(0,0); cout << count << endl; } return 0; }