###### 动态规划：E - Largest Rectangle in a Histogram（即HDU 1506）

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<set>
#include<vector>
#include<stack>
#include<ctime>
#include<cstdlib>
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;
using namespace std;
int h[100005],dpl[100005],dpr[100005];
int main()
{
int n,i,j;
while(scanf("%d",&n)&&n)
{
for(i=1; i<=n; i++)
scanf("%d",&h[i]);
for(i=1,j=n; i<=n,j>=1; i++,j--)
{
dpl[i]=i;
dpr[j]=j;
while(dpl[i]>1&&h[dpl[i]-1]>=h[i])
dpl[i]=dpl[dpl[i]-1];
while(dpr[j]<n&&h[dpr[j]+1]>=h[j])
dpr[j]=dpr[dpr[j]+1];
}
ll m=-1;
for(i=1; i<=n; i++)
m=max(m,(ll)h[i]*(dpr[i]-dpl[i]+1));
cout<<m<<endl;
}
return 0;
}


#### HDU 1506(Largest Rectangle in a Histogram)动态规划

2015-08-10 15:24:37

#### hdu - 1506 - Largest Rectangle in a Histogram（dp / 单调栈）

2014-11-01 08:46:21

#### HDU-1506 Largest Rectangle in a Histogram（单调栈）

2017-07-18 16:07:15

#### 【单调栈】hdu1506 Largest Rectangle in a Histogram ----简单了解单调栈

2017-03-21 12:08:07

#### POJ 2559 Largest Rectangle in a Histogram -- 动态规划

2014-03-06 09:25:29

#### LeetCode84 Largest Rectangle in Histogram java题解

2015-06-27 11:21:16

#### leetcode_question_85 Largest Rectangle in Histogram

2013-09-18 14:00:28

#### POJ-2559-Largest Rectangle in a Histogram-单调栈

2015-08-25 22:37:11

#### LeetCode Largest Rectangle in Histogram又一个极品程序

2013-12-27 08:45:21

#### 【POJ2559】Largest Rectangle in a Histogram

2016-08-21 11:05:57