题目链接:http://poj.org/problem?id=1321
智商不够了擦……我写的是逐点搜索,果断写屎了……逐行搜索过了。。。不行……逐点搜索我明天要再写一写……
view code
1 #include <iostream>
2 #include <cstdio>
3 #include <cstdlib>
4 #include <cstring>
5 #include <cmath>
6 #include <algorithm>
7 using namespace std;
8 int G[10][10], n, m, ans, f[10];
9 char s[10][10];
10 void init()
11 {
12 for (int i = 0; i < n; i++)
13 for (int j = 0; j < n; j++)
14 if (s[i][j] == '#') G[i][j] = 1;
15 else G[i][j] = 0;
16 }
17 void dfs(int dep, int k)
18 {
19 if (k == m)
20 {
21 ans++; return;
22 }
23 if (dep > n) return;
24 for (int j = 0; j < n; j++)
25 {
26 if (G[dep][j] && !f[j])
27 {
28 f[j] = 1;
29 dfs(dep + 1, k + 1);
30 f[j] = 0;
31 }
32 }
33 dfs(dep + 1, k);
34 return;
35 }
36 int main()
37 {
38 while (~scanf("%d%d", &n, &m))
39 {
40 if (n == -1 && m == -1) break;
41 memset(f, 0, sizeof(f));
42 for (int i = 0; i < n; i++) scanf("%s", s[i]);
43 init();
44 ans = 0;
45 dfs(0, 0);
46 printf("%d\n", ans);
47 }
48 return 0;
49 }
50