Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 深搜

Posted by hustcswgy at 2011-07-29 17:47:39 on Problem 1321
```#include<stdio.h>

int board[9][9];

unsigned long int search(int k, int l, int n, char state);

int main()
{
int n, k;
while(scanf("%d%d", &n, &k), n != -1)
{
int i, j;
for(i = 1; i <= n; i ++)
{
char tmp[10];
scanf("%s", tmp + 1);
for(j = 1; j <= n; j ++)
if(tmp[j] == '#') board[i][j] = 1;
else board[i][j] = 0;
}
printf("%lu\n", search(k, 1, n, 0xff));
}
return 0;
}

unsigned long int search(int k, int l, int n, char state)
{
int i, j;
unsigned long int sum = 0;
if(k == 0) return 1; /* 棋子无 */
if(k > n - l + 1) return 0; /* 棋盘无 */
for(i = l; i <= n; i ++)
for(j = 1; j <= n; j ++)
if(state & (0x80 >> (j - 1)) && board[i][j])
sum += search(k - 1, i + 1, n, state & ~(0x80 >> (j - 1))); /* 乃格兰！一开始i写成l，半天才看出来 */
return sum;
}
```

Followed by: