[Solution to a problem / template] hanging line method luogu_P1169_ board production (suspension line method

Provided $ lt [i] [j] $ is the furthest point to the left reaches, $ rt $ Similarly, $ ht [i] [j] $ extended up to the farthest tall

Start by setting the initial value for their position, height 1

Pretreatment extended around each point range, determined according to the subject extended condition

You can then dp:

lt[i][j]=max(lt[i][j],lt[i-1][j]);
rt[i][j]=min(rt[i][j],rt[i-1][j]);
ht[i][j]=ht[i-1][j]+1;

Specific can see other blog

#include<bits/stdc++.h>
using namespace std;
const int maxn=2009;
int n,m,ans1,ans2;
int lt[maxn][maxn],rt[maxn][maxn],ht[maxn][maxn],mp[maxn][maxn];
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++){
        scanf("%d",&mp[i][j]);
        lt[i][j]=rt[i][j]=j;
        ht[i][j]=1;
    }
    for(int i=1;i<=n;i++)
    for(int j=2;j<=m;j++)
    if(mp[i][j]!=mp[i][j-1])
    lt[i][j]=lt[i][j-1];
    
    for(int i=1;i<=n;i++)
    for(int j=m-1;j>=1;j--)
    if(mp[i][j]!=mp[i][j+1])
    rt[i][j]=rt[i][j+1];
    
    for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++){
        if(i>1 && mp[i][j] !=mp[i-1][j]){
            lt[i][j]=max(lt[i][j],lt[i-1][j]);
            rt[i][j]=min(rt[i][j],rt[i-1][j]);
            ht[i][j]=ht[i-1][j]+1;
        }
        int a=rt[i][j]-lt[i][j]+1;
        int b=min(a,ht[i][j]);
        ans1=max(ans1,b*b);
        ans2=max(ans2,a*ht[i][j]);
    }
    printf("%d\n%d",ans1,ans2);
}

 

Guess you like

Origin www.cnblogs.com/superminivan/p/11536188.html