记录动态规划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. C#版-百度网盘API的实现(一)

    在这篇文章中,楼主将会给大家介绍一下,通过C# winform程序在后台模拟用户登陆百度网盘的基本思路 首先了解下模拟登陆的流程,如下: 一,访问http://www.baidu.com网站,获取BA ...

  2. ElasticSearch Aggregation

    http://zaiste.net/2014/06/concisely_about_aggregations_in_elasticsearch/

  3. discuz函数quote

    public static function quote($str, $noarray = false) { if (is_string($str)) return '\'' . addcslashe ...

  4. 备机大地院系项目dataguard archived_log及standby_log

    主库archivelog及standbylog 仅仅是测试4天的数据,项目并未正式上线/data/dddb/DBSoftware/app/oracle/product/11.2.0/dbhome_1/ ...

  5. 网易云课堂_C语言程序设计进阶_第5周:链表

    5.1可变数组 5.2链表 5.1可变数组 Resizable Array Think about a set of functions that provide a mechanism of res ...

  6. 07.31 zepto

    tag事件 viewport标签 flexbox弹性布局 响应式布局 rem 交互优化 touchstart touchend 高清图片 1px  单文本溢出  多文本溢出

  7. HDU 3046 Pleasant sheep and big big wolf(最小割)

    HDU 3046 Pleasant sheep and big big wolf 题目链接 题意:一个n * m平面上,1是羊.2是狼,问最少要多少围墙才干把狼所有围住,每有到达羊的路径 思路:有羊和 ...

  8. TabHost 简单用法

    package com.google.tabhost;    import android.app.TabActivity;  import android.os.Bundle;  import an ...

  9. dataset 用法(1)

    DataSet是表和列结构在内存中的表示方式,DataSet支持多表.表间关系.数据约束等,和关系数据库的模型基本一致.(本质上是微型的数据库.包含一组DataTable对象和DataTable之间的 ...

  10. JavaScript之怎样获取元素节点

    JavaScript获取元素节点一共有三种方法,分别是通过元素ID.通过标签名字和通过类名字来获取: 1.通过元素ID属性的ID值来获得元素对象-getElementById() DOM提供了一个名为 ...