题目链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=15505

  每个h[i]维护两个值l[i]和r[i],分别表示大于h[i]的左边最远距离和小于h[i]的右边最远距离,DP转一下,然后直接求。。

 //STATUS:C++_AC_80MS_1360KB
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long LL; const int N=; int l[N],r[N],h[N];
int n; int main(){
// freopen("in.txt","r",stdin);
int i,j;
LL ans;
while(~scanf("%d",&n) && n)
{ for(i=;i<=n;i++){
scanf("%d",&h[i]);
}
h[]=-;
for(i=;i<=n;i++){
for(j=i;h[j-]>=h[i];j=l[j-]);
l[i]=j;
}
h[n+]=-;
for(i=n;i>;i--){
for(j=i;h[j+]>=h[i];j=r[j+]);
r[i]=j;
}
ans=;
for(i=;i<=n;i++){
ans=max(ans,(LL)h[i]*(r[i]-l[i]+));
} printf("%lld\n",ans);
}
return ;
}

BNUOJ-15505 Largest Rectangle in a Histogram DP的更多相关文章

  1. hdu---1506(Largest Rectangle in a Histogram/dp最大子矩阵)

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

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

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

  3. HDU1506 ( Largest Rectangle in a Histogram ) [dp]

    近期情绪太不稳定了.可能是由于在找实习这个过程碰壁了吧.第一次面试就跪了,可能是我面的是一个新公司,制度不完好,我感觉整个面试过程全然不沾编程,我面试的还是软件开发-后来我同学面试的时候.说是有一道数 ...

  4. Largest Rectangle in a Histogram(dp)

    http://acm.hdu.edu.cn/showproblem.php?pid=1506 题意:给出n个矩形的高度,每个矩形的宽都为1,求相邻的矩形能组合成的最大的矩形的面积. 思路:求出比第i个 ...

  5. hdu 1506 Largest Rectangle in a Histogram ((dp求最大子矩阵))

    # include <stdio.h> # include <algorithm> # include <iostream> # include <math. ...

  6. Largest Rectangle in a Histogram(DP)

    Largest Rectangle in a Histogram Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K ...

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

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

  8. POJ 2559 Largest Rectangle in a Histogram (单调栈或者dp)

    Largest Rectangle in a Histogram Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15831 ...

  9. NYOJ-258/POJ-2559/HDU-1506 Largest Rectangle in a Histogram,最大长方形,dp或者单调队列!

                                         Largest Rectangle in a Histogram 这么经典的题硬是等今天碰到了原题现场懵逼两小时才会去补题.. ...

随机推荐

  1. Android 二维码扫描与生成

    由于源代码比较多,本文不进行讲述,请下载源码. 源码来源于网络,请点击这里下载: http://files.cnblogs.com/wuyou/Android%E4%BA%8C%E7%BB%B4%E7 ...

  2. [扫描线]POJ2932 Coneology

    题意:有n个圆 依次给了半径和圆心坐标  保证输入的圆不相交(只有 相离 和 内含/外含 的情况)   问 有几个圆 不内含在其他圆中,并分别列出这几个圆的编号(1~n) (n的范围是[1, 4000 ...

  3. vs2015 打不开了 提示"CSharpPackage",未能正确加载xx包

    原文:vs2015 打不开了 提示"CSharpPackage" 最近发现vs2015 在新建项目和加载现有项目的时候会报错 提示 开始我以为是系统的问题导致vs 配置除了问题,重 ...

  4. How to download apk for google play online?

    http://apps.evozi.com/apk-downloader/ Online APK Downloader http://apkpure.com/ apkpure http://www.c ...

  5. Exynos 4412的启动过程分析[2]

    做实验时我们是把 bin 文件烧入SD卡,比如前面做的汇编流水灯实验. 问:是谁把这些指令从 SD 卡读出来执行? 答:是固化在芯片内部ROM上的代码---它被称为iROM ,iROM是厂家事先烧写在 ...

  6. tcp连接的3次握手

    http://www.tcpipguide.com/free/t_TCPConnectionEstablishmentProcessTheThreeWayHandsh-3.htm synchronou ...

  7. Where is Vasya?

    Where is Vasya? Vasya stands in line with number of people p (including Vasya), but he doesn't know ...

  8. linux 进程间消息队列通讯

    转自:http://blog.csdn.net/lifan5/article/details/7588529 http://www.cnblogs.com/kunhu/p/3608589.html 前 ...

  9. maven常用插件配置详解

    常用插件配置详解Java代码    <!-- 全局属性配置 --> <properties> <project.build.name>tools</proje ...

  10. poj 3009 Curling 2.0( dfs )

    题目:http://poj.org/problem?id=3009 参考博客:http://www.cnblogs.com/LK1994/ #include <iostream> #inc ...