Fire Net HDU 1045

时间:2020-12-25 16:08:16

简单深搜,可以完全暴力,不会超时的。

#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
#define MAX(a,b) (a>b?a:b)
char maze[][];
int n, maxn; void DFS(int step,int count);
int cheak(int x, int y);
int main()
{
int i;
while(scanf("%d",&n), n)
{
maxn = ;
for(i = ; i < n; i++)
scanf("%s",maze[i]);
DFS(,);
printf("%d\n",maxn);
}
return ;
} void DFS(int step,int count)
{
int x, y;
maxn = MAX(maxn,count);
if(step == n*n)
return ;
x = step/n;
y = step%n;
if(maze[x][y] == '.' && cheak(x,y))
{
maze[x][y] = 'O';
DFS(step+,count+);
maze[x][y] = '.';
}
DFS(step + , count);
} int cheak(int x, int y)
{
int i;
for(i = x-; i >= ; i--)
{
if(maze[i][y] == 'O')
return ;
else if(maze[i][y] == 'X')
break;
}
for(i = y-; i >= ; i--)
{
if(maze[x][i] == 'O')
return ;
else if(maze[x][i] == 'X')
break;
}
return ;
}