zoukankan      html  css  js  c++  java
  • 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
    ",3*ans);
        }
        return 0;
    }
  • 相关阅读:
    html5-css渐变色
    html5-css综合练习
    html5-css背景
    html5-css边框全
    html5-css边框img
    进程控制(二)与linux下的自有服务
    进程检测与控制(一)
    权限及软件包管理
    linux下文件权限管理
    vim及用户组管理
  • 原文地址:https://www.cnblogs.com/zufezzt/p/5448131.html
Copyright © 2011-2022 走看看