-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1321.cpp
More file actions
66 lines (57 loc) · 1.28 KB
/
1321.cpp
File metadata and controls
66 lines (57 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*************************************************************************
> File Name: 1321.cpp
> Author: dulun
> Mail: [email protected]
> Created Time: 2016年01月16日 星期六 23时15分27秒
************************************************************************/
#include<iostream>
#include<stdio.h>
using namespace std;
bool list[10] = {0};
int n, k, count, num;
int chess[10][10] = {0};
void init()
{
for(int j = 0; j < n; j++) list[j] = 0;
}
void dfs(int index)
{
if(k == num) {count ++; return ;}
if(index >= n) return;
for(int i = 0; i < n; i++)
{
if(chess[index][i] == 1 && list[i] == 0)
{
list[i] = 1;
num++;
dfs(index+1);
list[i] = 0;
num--;
}
}
dfs(index+1);
}
int main()
{
int cnt = 0;
int ans[100];
while(cin>>n>>k)
{
count = 0;
if(n == k && k == -1) break;
char ch;
init();
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
{
cin>>ch;
if(ch == '#') chess[i][j] = 1;
if(ch == '.') chess[i][j] = -1;
}
dfs(0);
ans[cnt++] = count;
}
for(int i = 0; i < cnt; i++)
printf("%d\n", ans[i]);
return 0;
}