luogu 4147 玉蟾宫 悬线DP
Code:
#include<bits/stdc++.h> using namespace std; #define setIO(s) freopen(s".in","r",stdin) #define maxn 1002 int n,m; int mk[maxn][maxn],l[maxn][maxn],r[maxn][maxn],up[maxn][maxn]; char str[maxn]; int main() { // setIO("input"); scanf("%d%d",&n,&m); for(int i=1;i<=n;++i) { for(int j=1;j<=m;++j) { scanf("%s",str+1); if(str[1]=='F') mk[i][j]=up[i][j]=1,l[i][j]=r[i][j]=j; } } for(int i=1;i<=n;++i) for(int j=2;j<=m;++j) if(mk[i][j]&&mk[i][j-1]) l[i][j]=l[i][j-1]; for(int i=1;i<=n;++i) for(int j=m-1;j>=1;--j) if(mk[i][j]&&mk[i][j+1]) r[i][j]=r[i][j+1]; int ans=0; for(int i=1;i<=n;++i) { for(int j=1;j<=m;++j) { if(i>1 && mk[i][j] && mk[i-1][j]) { up[i][j]=up[i-1][j]+1; l[i][j]=max(l[i][j],l[i-1][j]); r[i][j]=min(r[i][j],r[i-1][j]); } ans=max(ans, (r[i][j]-l[i][j]+1)*up[i][j]); } } printf("%d\n",ans*3); return 0; }