记录动态规划dpl,dpr,分辨记录i左面的比i大的,右面比i大的,然后(dpr[i]-dpl[i]+1)*h[i]得出长度

动态转移方程while(temp>1 && h[temp-1]>=h[i]) temp=dpl[temp-1]

/*************************************************************************
> File Name: hdu1506.cpp
> Author: yang
> Mail:826123027@qq.com
> Created Time: 2014年08月24日 星期日 23:41:16
************************************************************************/ #include<iostream>
#include<stdio.h>
#include<memory.h>
using namespace std;
#define N 100005
int main(){
int dpl[N],dpr[N];
long long h[N];
int n;
while(scanf("%d",&n),n){
for(int i=1;i<=n;i++)
scanf("%lld",&h[i]);
dpl[1]=1;
int temp;
for(int i=2;i<=n;i++){
temp=i;
while(temp>1 && h[temp-1]>=h[i]) temp=dpl[temp-1];
dpl[i]=temp;
}
dpr[n]=n;
for(int i=n-1;i>=1;i--){
temp=i;
while(temp<n && h[i]<=h[temp+1]) temp=dpr[temp+1];
dpr[i]=temp;
}
long long sum,ans=0;
for(int i=1;i<=n;i++){
// cout<<dpl[i]<<" "<<dpr[i]<<endl; sum=(dpr[i]-dpl[i]+1)*h[i];
// cout<<"sum:"<<sum<<endl;
if(sum>ans) ans=sum;
}
cout<<ans<<endl;
}
}

hdu 1507 Largest Rectangle in a Histogram 动态规划计算最大面积的更多相关文章

  1. HDU 1506 Largest Rectangle in a Histogram (dp左右处理边界的矩形问题)

    E - Largest Rectangle in a Histogram Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format: ...

  2. HDU 1506 Largest Rectangle in a Histogram set+二分

    Largest Rectangle in a Histogram Problem Description: A histogram is a polygon composed of a sequenc ...

  3. Largest Rectangle in a Histogram(最大矩形面积,动态规划思想)

    Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  4. hdu 1506 Largest Rectangle in a Histogram 构造

    题目链接:HDU - 1506 A histogram is a polygon composed of a sequence of rectangles aligned at a common ba ...

  5. HDU 1506 Largest Rectangle in a Histogram(DP)

    Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  6. HDU 1506 Largest Rectangle in a Histogram(区间DP)

    题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=1506 题目: Largest Rectangle in a Histogram Time Limit: ...

  7. DP专题训练之HDU 1506 Largest Rectangle in a Histogram

    Description A histogram is a polygon composed of a sequence of rectangles aligned at a common base l ...

  8. Hdu 1506 Largest Rectangle in a Histogram 分类: Brush Mode 2014-10-28 19:16 93人阅读 评论(0) 收藏

    Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

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

    题目地址:http://poj.org/problem?id=2559 Description A histogram is a polygon composed of a sequence of r ...

随机推荐

  1. ASP.NET页面跳转

    总结一下跳转方式: <a>标签 <a href=”home.aspx”></a> HyperLink控件 Asp.net 服务器端控件 属性NavigateUrl指 ...

  2. 一些CSS命名规则

    一些CSS命名规则 头:header 内容:content/containe 尾:footer 导航:nav 侧栏:sidebar 栏目:column 页面外围控制整体布局宽度:wrapper 左右中 ...

  3. SQL Server 触发器的修改与删除

    修改: alter trigger trigger_name on ..... as .....   #把create 修成  alter 就可以了. 删除: drop trigger trigger ...

  4. SQL Server 一些重要视图3

    1. sys.dm_tran_locks; 为每一把锁返回一行.request_session_id 可以与sys.dm_tran_session_transactions \sys.dm_exec_ ...

  5. [LeetCode][Python]17: Letter Combinations of a Phone Number

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 17: Letter Combinations of a Phone Numb ...

  6. linux学习 建立静态库,动态库,写简单的makefile

    建立静态库 建立四个文件 bin(可运行文件),lib(库),include(头文件),src(放源文件) 这里的起的库明为add 在src文件里运行 1)gcc -c add.c //编译add.c ...

  7. 一个SQL update语句

    须要每隔一段时间选取最老的商户更新时间戳: update DP_Shop set DP_Shop.LastDate = now() where DP_Shop.ShopId in (select Sh ...

  8. 关于cocos2d安装时编译不成功(个人心得)

    在解压cocos2d执行vs2010.sln时错误发生不能成功生成.遇到这样的错误: 1>c:\program files\microsoft sdks\windows\v7.0a\includ ...

  9. C#深复制和浅复制

    本文在于巩固基础 我们来看看什么是深复制.浅复制: C#中对于数据的复制机制虽然简单但是容易让人误解.C#数据类型大体分为值类型(value type)与引用类型(reference type).对于 ...

  10. 2.1确定一个char包含何种字符

    知识点: 1.char.IsControl 2.char.IsPunctuation 3.char.IsSurrogate 4.char.IsWhitespace 5.char.IsDigit 6.c ...