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 cui715715 at 2007-08-24 15:20:05 on Problem 1321
#include <cstdio>
#include <iostream>
using namespace std;
int result,n,k;
char mp[10][10];
int visrow[10],viscol[10];
void dfs(int row,int leftchess)
{
     int col;
     for (col=0;col<n;col++)
     {
         if (mp[row][col] == '#' && !visrow[row] && !viscol[col])
         {
                          visrow[row] = 1;
                          viscol[col] = 1;
                          leftchess--;
                          if ((row + 1) < n && leftchess > 0) dfs(row + 1,leftchess);
                             else if (leftchess == 0) result++;
                          leftchess++;
                          visrow[row] = 0;
                          viscol[col] = 0;
         }
     }
}

int main()
{
    int k,i,j;
    while (scanf("%d%d",&n,&k) != EOF)
    {
          getchar();
          if (n + k == -2) return 0;
          for (i=0;i<n;i++)
              gets(mp[i]);
          memset(visrow,0,sizeof(visrow));
          memset(viscol,0,sizeof(viscol));
          result = 0;
          for (i=0;i<n;i++)
              dfs(i,k);
          printf("%d\n",result);
    }
return 0;
}


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