Analysis: The mark of the fort is ' @ ' (backtracking to restore) recursion, the next traversal in four directions (one row or column), find ' @ ' is marked as no, if found ' X ' or the boundary is marked as a row.
This problem seems to be possible to do with a two-point match.
#include <iostream>using namespace std; #define N 5char map[n][n];int dir[4][2]={-1,0,0,-1,1,0,0,1};int N,max; BOOL Judge (int x,int y) {int i,tx,ty;for (i=0;i<4;i++) {Tx=x;ty=y;while (true) //extends Outward { tx=tx+dir[i][0]; TY=TY+DIR[I][1]; if (map[tx][ty]== ' @ ') return false; else if (map[tx][ty]== ' X ') break ; else if (tx< 1 | | ty<1 | | tx>n | | ty>n) break ;}} return true;} void dfs (int num) {int i,j;for (i=1;i<=n;i++) for (j=1;j<=n;j++) if (map[i][j]== '. ' && judge (I,j)) {Map[i][j ]= ' @ ';d FS (num+1); map[i][j]= '. ';} if (max<num) //Get maximum value max=num;} int main () {int I,j;while (cin>>n,n) {for (i=1;i<=n;i++) for (j=1;j<=n;j++) cin>>map[i][j];max= 0;dfs (0); Cout<<max<<endl;} return 0; }
HDU ACM 1045 Fire Net Brute Force search