Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  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:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator