标签:
Description
Input
Output
Sample Input
7 2 1 4 5 1 3 3 4 1000 1000 1000 1000 0
Sample Output
#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> using namespace std; const int maxn=100005; typedef long long int ll; ll l[maxn],r[maxn],h[maxn]; int main(){ int n; while(scanf("%d",&n)!=EOF){ if(!n) break; memset(l,0,sizeof(l)); memset(r,0,sizeof(r)); memset(h,0,sizeof(h)); // memset(dp,0,sizeof(dp)); for(int i=1;i<=n;i++){ scanf("%lld",&h[i]); } l[1]=1; r[n]=n; for(int i=2;i<=n;i++){ int tmp=i; while(tmp>1&&h[i]<=h[tmp-1]) tmp=l[tmp-1]; l[i]=tmp; } for(int i=n-1;i>=1;i--){ int tmp=i; while(tmp<n&&h[i]<=h[tmp+1]) tmp=r[tmp+1]; r[i]=tmp; } ll ans=-1; for(int i=1;i<=n;i++){ ll tmp=(r[i]-l[i]+1)*h[i]; ans=max(ans,tmp); } printf("%lld\n",ans); } return 0; }
HDU 1506 Largest Rectangle in a Histogram (dp左右处理边界的矩形问题)
标签:
原文地址:http://www.cnblogs.com/13224ACMer/p/4984750.html