HDU 1505 City Game

最大全1子矩阵面积*3

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

const int maxn=2000+10;
int a[maxn];
int L[maxn],R[maxn];
int m,n;
int tmp[maxn][maxn],b[maxn][maxn];

void f()
{
    for(int i=1; i<=n; i++) L[i]=i;
    for(int i=2; i<=n; i++)
    {
        if(a[i]>a[i-1]) continue;
        int pre=L[i-1];
        while(1)
        {
            L[i]=pre;
            if(pre==1||a[pre-1]<a[i]) break;
            pre=L[pre-1];
        }
    }

    for(int i=n; i>=1; i--) R[i]=i;
    for(int i=n-1; i>=1; i--)
    {
        if(a[i]>a[i+1]) continue;
        int pre=R[i+1];
        while(1)
        {
            R[i]=pre;
            if(pre==n||a[pre+1]<a[i]) break;
            pre=R[pre+1];
        }
    }
}

int main()
{
    int T; scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d",&n,&m);
        memset(b,0,sizeof b);
        for(int i=1; i<=n; i++)
            for(int j=1; j<=m; j++)
            {
                char op[5]; scanf("%s",op);
                if(op[0]=='F') tmp[i][j]=1;
                else tmp[i][j]=0;
            }
        for(int i=1; i<=n; i++)
            for(int j=1; j<=m; j++)
            {
                if(tmp[i][j]==0) continue;
                b[i][j]=b[i][j-1]+tmp[i][j];
            }

        int ans=0;
        for(int j=1;j<=m;j++)
        {
            for(int i=1;i<=n;i++) a[i]=b[i][j];
            f();
            for(int i=1;i<=n;i++) ans=max(ans,a[i]*(R[i]-L[i]+1));
        }
        printf("%d\n",3*ans);
    }
    return 0;
}

 

posted @ 2016-04-30 09:22  Fighting_Heart  阅读(231)  评论(0编辑  收藏  举报