POJ 1506 Largest Rectangle in a Histogram (dp的思想)
2013-08-24 14:13
381 查看
POJ 1506 Largest Rectangle in a Histogram (dp的思想)
#include <iostream> #include <cstdio> #include <queue> #include <cmath> using namespace std; const int maxn=100010; unsigned long long a[maxn],l[maxn],r[maxn]; int n; void computing(){ unsigned long long ans=0; l[0]=0;r[n-1]=n-1; for(int i=1;i<n;i++){ int pos=i; while(pos>0 && a[pos-1]>=a[i]) pos=l[pos-1]; l[i]=pos; } for(int i=n-2;i>=0;i--){ int pos=i; while(pos<n-1 && a[pos+1]>=a[i]) pos=r[pos+1]; r[i]=pos; } for(int i=0;i<n;i++){ ans=max( (r[i]-l[i]+1)*a[i] , ans); } cout<<ans<<endl; } int main(){ while(scanf("%d",&n)!=EOF && n>0){ for(int i=0;i<n;i++) scanf("%I64d",&a[i]); computing(); } return 0; }
相关文章推荐
- POJ 1506 Largest Rectangle in a Histogram (dp的思想)
- hdu 1506 Largest Rectangle in a Histogram (dp思想)
- NYOJ-258/POJ-2559/HDU-1506 Largest Rectangle in a Histogram,最大长方形,dp或者单调队列!
- HDU 1506 Largest Rectangle in a Histogram【DP】
- HDU 1506 Largest Rectangle in a Histogram(dp求最大子矩阵和)
- hdu 1506 Largest Rectangle in a Histogram ((dp求最大子矩阵))
- Largest Rectangle in a Histogram (poj 2559 && hdu 1506 矩形系列 迭代法)
- hdu 1506 Largest Rectangle in a Histogram(dp)
- hdu 1506 (dp) Largest Rectangle in a Histogram
- POJ 2559 / HDU 1506 / LightOJ 1083 Largest Rectangle in a Histogram (单调栈)
- Largest Rectangle in a Histogram - HDU 1506 dp
- POJ 2559 Largest Rectangle in a Histogram + POJ 2082Terrible Sets(DP/单调栈)
- POJ 2559 Largest Rectangle in a Histogram (单调栈或者dp)
- HDU 1506 Largest Rectangle in a Histogram dp
- [dp]POJ2559 && HDOJ1506 Largest Rectangle in a Histogram
- poj 2559 Largest Rectangle in a Histogram dp!!!
- hdu 1506 Largest Rectangle in a Histogram(DP)
- POJ2559——DP——Largest Rectangle in a Histogram
- HDU-1506 (POJ-2599) Largest Rectangle in a Histogram (单调栈)
- hdoj 1506 | poj 2559 Largest Rectangle in a Histogram