标签:code div header href container names eof name map
AC代码:
#include<iostream>
using namespace std;
int n;
int ans;
char map[10][10];
bool check(int x,int y);
void dfs(int point,int sum);
int main()
{
while(scanf("%d",&n)!= EOF)
{
if(n==0)
break;
getchar();
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
scanf("%c",&map[i][j]);
getchar();
}
ans = 0;
dfs(0,0);
printf("%d\n",ans);
}
return 0;
}
bool check(int x,int y)
{
bool flag = true;
for(int i=x;i>=0;i--)
{
if(map[i][y]==‘X‘)
break;
else if(map[i][y]==‘b‘)
{
flag = false;
break;
}
}
for(int i=y;i>=0;i--)
{
if(map[x][i]==‘X‘)
break;
else if(map[x][i]==‘b‘)
{
flag = false;
break;
}
}
return flag;
}
void dfs(int point,int sum)
{
if(point == n*n)
{
if(sum>ans)
ans = sum;
return;
}
int x = point/n;
int y = point%n;
if(map[x][y]==‘.‘&&check(x,y))
{
map[x][y]=‘b‘;
dfs(point+1,sum+1);
map[x][y]=‘.‘;
}
dfs(point+1,sum);
}
标签:code div header href container names eof name map
原文地址:https://www.cnblogs.com/CuteyThyme/p/12678691.html