• hdu1506 Largest SubMatrix


    一次ac,难的呀,和之前做的01最大矩阵差不多的,再加一维记录多'a','b','c'的每种情况的高度

    #include <iostream>
    #include <cstdio>
    #include <cmath>
    #include <cstdlib>
    #include <cstring>
    #include <algorithm>
    #include <string>
    #include <stack>
    #include <queue>
    
    const int inf = (1<<31)-1;
    const int MAXN = 1e3+10;
    using namespace std;
    
    char s[MAXN];
    int a[MAXN][MAXN][3];
    int L[MAXN][3];
    int R[MAXN][3];
    
    int main()
    {
        int n,m;
        while(scanf("%d%d",&n,&m)==2){
            memset(a,0,sizeof(a));
            for(int i=1;i<=n;i++){
                scanf("%s",s);
                for(int j=0;j<m;j++){
                    if(s[j]=='a'||s[j]=='y'||s[j]=='w'||s[j]=='z')a[i][j+1][0] = a[i-1][j+1][0]+1;
                    if(s[j]=='b'||s[j]=='x'||s[j]=='w'||s[j]=='z')a[i][j+1][1] = a[i-1][j+1][1]+1;
                    if(s[j]=='c'||s[j]=='x'||s[j]=='y'||s[j]=='z')a[i][j+1][2] = a[i-1][j+1][2]+1;
                }
            }
            int ans,mmax = -inf;
            for(int i=1;i<=n;i++){
    
                a[i][0][0] = a[i][0][1] = a[i][0][2] = -1;
                a[i][m+1][0] = a[i][m+1][1] = a[i][m+1][2] = -1;
    
                for(int j=1;j<=m;j++){
                    //L[j][0]=L[j][1] = L[j][2] = j;
                    for(int k=0;k<3;k++){
                        L[j][k] = j;
                        while(a[i][j][k]<=a[i][L[j][k]-1][k])
                            L[j][k] = L[L[j][k]-1][k];
                    }
                }
                for(int j=m;j>=1;j--){
                    for(int k=0;k<3;k++){
                        R[j][k] = j;
                        while(a[i][j][k]<=a[i][R[j][k]+1][k])
                            R[j][k] = R[R[j][k]+1][k];
                    }
                }
                for(int j=1;j<=m;j++){
                    for(int k=0;k<3;k++){
                        ans = (R[j][k]-L[j][k]+1)*a[i][j][k];
                        mmax = max(ans,mmax);
                    }
                }
            }
            cout<<mmax<<endl;
        }
        //cout << "Hello world!" << endl;
        return 0;
    }
    View Code

     只能说模板真好用

    在一个谎言的国度,沉默就是英雄
  • 相关阅读:
    [NOI2009]管道取珠
    Rebalance再均衡
    生产者分区写入策略
    Kafka事务
    幂等性
    消费者组
    Kafka中的重要概念
    偏移量offset
    服务注册和发现的意思,Spring cloud如何实现?
    负载平衡的意义
  • 原文地址:https://www.cnblogs.com/EdsonLin/p/5389105.html
Copyright © 2020-2023  润新知