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

注意行和列一定要是局部变量,要不是无法还原,附AC代码(C语言)

Posted by sunny1995 at 2014-12-16 19:24:33 on Problem 1321
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int n,k,i,j,l[10];
long cnt=0;

char grids[10][10];

void dfs(int a,int b)
{
	int i0,j0;
    if (b==0)
    {
       cnt++;
	   return;
    }
	for (j0=a+1;j0<=n-1;j0++)
       for (i0=0;i0<=n-1;i0++)
       if (l[i0]&&grids[j0][i0]=='#')
       {
          l[i0]=0;
		  b--;
          dfs(j0,b);
		  b++;
		  l[i0]=1;
       }
}

int main()
{
    char u;
	do{
	   cnt=0;
       scanf("%d%d",&n,&k);
	   if (n==-1&&k==-1)
		   break;
       scanf("%c",&u);
	   memset(l,1,sizeof(l));
       for (i=0;i<=n-1;i++)
       for (j=0;j<=n;j++)
         scanf("%c",&grids[i][j]);
       dfs(-1,k);
       printf("%d\n",cnt);
	   }while(1);
       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