这个题要你求出最大的子矩阵,其中子矩阵必须全为F
用3个数组进行记录状态即可。
代码:
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int maxn=1001;
int m,n,up[maxn][maxn],_left[maxn][maxn],_right[maxn][maxn];
char map[maxn][maxn];
int main()
{
int cas;
scanf("%d",&cas);
while(cas--)
{
scanf("%d%d",&n,&m);
int ans=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
char ch;
while(ch=getchar())
{
if(ch=='R'||ch=='F')
break;
}
map[i][j]=ch;
}
}
for(int i=0;i<n;i++)
{
int pos_left=-1,pos_right=m;
for(int j=0;j<m;j++)
{
if(map[i][j]=='R') {up[i][j]=_left[i][j]=0;pos_left=j;}
else
{
up[i][j]=i==0?1:up[i-1][j]+1;
_left[i][j]=i==0?pos_left+1:max(_left[i-1][j],pos_left+1);
}
}
for(int j=m-1;j>=0;j--)
{
if(map[i][j]=='R'){_right[i][j]=n;pos_right=j;}
else
{
_right[i][j]=i==0?pos_right-1:min(_right[i-1][j],pos_right-1);
}
ans=max(ans,up[i][j]*(_right[i][j]-_left[i][j]+1));
}
}
printf("%d\n",ans*3);
}
return 0;
}