题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1505
题目意思:
给你一个矩阵,要你求出一个最大的矩阵,里面全部是F
然后用这个面积*3输出
解题思路:
我们枚举第i行作为底,在这个基础上,求最大的矩形面积
这样一转换,就和HDU1506的思路很像了
然后求出最大值
代码:
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int maxn = 1010;
char data[maxn][maxn];
int h[maxn][maxn];
int l[maxn];
int r[maxn];
int main()
{
int n,m;
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
cin>>data[i][j];
memset(h,0,sizeof(h));
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(data[i][j]=='F')
h[i][j] = h[i-1][j]+1;
}
}
int ans = -1;
for(int i=1;i<=n;i++)
{
l[1] = 1;
r[m] = m;
h[i][0] = -1;
h[i][m+1] = -1;
for(int j=2;j<=m;j++)
{
l[j] = j;
while(h[i][l[j]-1]>=h[i][j])
l[j] = l[l[j]-1];
}
for(int j=m-1;j>=1;j--)
{
r[j]=j;
while(h[i][r[j]+1]>=h[i][j])
r[j]=r[r[j]+1];
}
int tmp;
for(int j=1;j<=m;j++)
{
tmp = (r[j]-l[j]+1)*h[i][j];
if(tmp>ans)
ans = tmp;
}
}
printf("%d\n",ans*3);
}
return 0;
}