poj 1321棋盘问题(类似于八皇后问题)

#include <stdio.h>
#include
#include
#include
#include
using namespace std;
char map[10][10];
int a[9];
int n,k,res,cot;
void dfs(int index)
{
if(cotk)
{
res++;
return;
}
if(index>n)//超出棋盘返回
return ;
for(int i=1;i<=n;i++)
{
if(!a[i]&&map[index][i]
’#’)
{
a[i]=1;
cot++;
dfs(index+1);
a[i]=0;
cot–;
}
}
dfs(index+1);
}
int main()
{
while(cin>>n>>k)
{
if(n==-1&&k==-1)
break;
cot=0;
res=0;
memset(a,0,sizeof(a));
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
cin>>map[i][j];
}
dfs(1);
cout<<res<<endl;
}
return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_42424319/article/details/89158433