| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
回溯啊#include<stdio.h>
#include<stdlib.h>
char chess[10][10];
int row[10],col[10];
int n,k,count=0;
void Back(int,int,int);
int main(void)
{
int i;
while(scanf("%d%d",&n,&k)&&n!=-1&&k!=-1)
{
for(i=0;i<n;i++)
{
scanf("%s",chess[i]);
}
Back(1,0,0);
printf("%d\n",count);
count=0;
}
system("PAUSE");
return 0;
}
void Back(int w,int a,int b)
{
if(w>k)
{
count++;
}
else
{
int i,j;
for(i=a;i<n;i++)
{
for(j=b;j<n;j++)
{
if(chess[i][j]=='#'&&row[i]==0&&col[j]==0)
{
chess[i][j]='.';
row[i]=1;
col[j]=1;
Back(w+1,i,j);
chess[i][j]='#';
row[i]=0;
col[j]=0;
}
}
b=0;
}
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator