每个点16种状态,记忆化搜一下即可。。。
#include <iostream>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <time.h>
#define maxn 105
#define maxm 300005
#define eps 1e-10
#define mod 10000007
#define INF 1e9
#define lowbit(x) (x&(-x))
#define mp make_pair
#define ls o<<1
#define rs o<<1 | 1
#define lson o<<1, L, mid
#define rson o<<1 | 1, mid+1, R
typedef long long LL;
//typedef int LL;
using namespace std;
LL qpow(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base;base=base*base;b/=2;}return res;}
LL powmod(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base%mod;base=base*base%mod;b/=2;}return res;}
void scanf(int &__x){__x=0;char __ch=getchar();while(__ch==' '||__ch=='\n')__ch=getchar();while(__ch>='0'&&__ch<='9')__x=__x*10+__ch-'0',__ch = getchar();}
LL gcd(LL _a, LL _b){if(!_b) return _a;else return gcd(_b, _a%_b);}
// head
char g[maxn][maxn];
int dp[maxn][maxn][8][2];
int dir[8][2] = {{0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1}, {-1, -1}, {-1, 0}, {-1, 1}};
int n;
void init(void)
{
memset(g, '#', sizeof g);
memset(dp, -1, sizeof dp);
}
void read(void)
{
getchar();
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++)
g[i][j] = getchar();
getchar();
}
}
int dfs(int si, int sj, int d, int k)
{
if(g[si][sj] == '#') return dp[si][sj][d][k] = 0;
if(dp[si][sj][d][k] != -1) return dp[si][sj][d][k];
if(si <= 0 || sj <= 0 || si > n || sj > n) return 0;
int ti = si + dir[d][0];
int tj = sj + dir[d][1];
if(k == 0) dp[si][sj][d][k] = dfs(ti, tj, d, k) + 1;
else {
int tt = 0, dd;
tt = max(tt, dfs(ti, tj, d, 1));
dd = (d + 2) % 8;
ti = si + dir[dd][0];
tj = sj + dir[dd][1];
tt = max(tt, dfs(ti, tj, dd, 0));
dd = (d - 2 + 8) % 8;
ti = si + dir[dd][0];
tj = sj + dir[dd][1];
tt = max(tt, dfs(ti, tj, dd, 0));
dp[si][sj][d][k] = tt + 1;
}
return dp[si][sj][d][k];
}
void work(void)
{
int ans = 0;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
for(int d = 0; d < 8; d++)
for(int k = 0; k <= 1; k++)
ans = max(ans, dfs(i, j, d, k));
printf("%d\n", ans);
}
int main(void)
{
while(scanf("%d", &n), n != 0) {
init();
read();
work();
}
return 0;
}