hdu---1506(Largest Rectangle in a Histogram/dp最大子矩阵)
Largest Rectangle in a Histogram
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 11541 Accepted Submission(s): 3174
histogram is a polygon composed of a sequence of rectangles aligned at a
common base line. The rectangles have equal widths but may have
different heights. For example, the figure on the left shows the
histogram that consists of rectangles with the heights 2, 1, 4, 5, 1, 3,
3, measured in units where 1 is the width of the rectangles:

Usually,
histograms are used to represent discrete distributions, e.g., the
frequencies of characters in texts. Note that the order of the
rectangles, i.e., their heights, is important. Calculate the area of the
largest rectangle in a histogram that is aligned at the common base
line, too. The figure on the right shows the largest aligned rectangle
for the depicted histogram.
input contains several test cases. Each test case describes a histogram
and starts with an integer n, denoting the number of rectangles it is
composed of. You may assume that 1 <= n <= 100000. Then follow n
integers h1, ..., hn, where 0 <= hi <= 1000000000. These numbers
denote the heights of the rectangles of the histogram in left-to-right
order. The width of each rectangle is 1. A zero follows the input for
the last test case.
each test case output on a single line the area of the largest
rectangle in the specified histogram. Remember that this rectangle must
be aligned at the common base line.
0
#include<cstdio>
#include<cstring>
#define maxn 100005
__int64 ll[maxn],rr[maxn],hh[maxn];
int main()
{
int n,i,t;
while(scanf("%d",&n)&&n)
{
for(i=;i<=n;i++)
scanf("%I64d",&hh[i]);
ll[]=,rr[n]=n;
for(i=;i<=n;i++)
{
t=i;
while(t>&&hh[i]<=hh[t-])
t=ll[t-];
ll[i]=t;
}
for(i=n-;i>;i--)
{
t=i;
while(t<n&&hh[i]<=hh[t+])
t=rr[t+];
rr[i]=t;
}
__int64 res=;
for(i=;i<=n;i++)
{
if(res<(rr[i]-ll[i]+)*hh[i])
res=(rr[i]-ll[i]+)*hh[i];
}
printf("%I64d\n",res);
}
return ;
}
hdu---1506(Largest Rectangle in a Histogram/dp最大子矩阵)的更多相关文章
- HDU 1506 Largest Rectangle in a Histogram(DP)
Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- hdu 1506 Largest Rectangle in a Histogram ((dp求最大子矩阵))
# include <stdio.h> # include <algorithm> # include <iostream> # include <math. ...
- HDU 1506 Largest Rectangle in a Histogram (dp左右处理边界的矩形问题)
E - Largest Rectangle in a Histogram Time Limit:1000MS Memory Limit:32768KB 64bit IO Format: ...
- HDU 1506 Largest Rectangle in a Histogram(区间DP)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=1506 题目: Largest Rectangle in a Histogram Time Limit: ...
- 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 ...
- HDU 1506 Largest Rectangle in a Histogram set+二分
Largest Rectangle in a Histogram Problem Description: A histogram is a polygon composed of a sequenc ...
- 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 ...
- 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 ...
- hdu 1506 Largest Rectangle in a Histogram(单调栈)
L ...
随机推荐
- 【转载】C++内存分配
原文:C++内存分配 内存泄露相信对C++程序员来说都不陌生.解决内存泄露的方案多种多样,大部分方案以追踪检测为主,这种方法实现起来容易,使用方便,也比较安全. 首先我们要确定这个模块的主要功能: 能 ...
- shutdown命令
其实不需要使用软件,就可以实现自动关机或重启等功能的:Windows XP的关机是由Shutdown.exe程序来控制的,位于Windows\System32文件夹中.如 果想让Windows 200 ...
- So easy Webservice 4.Java方式访问WebService(使用jdk1.6以上 wsimport命令)
1.选中要调用的服务单击”服务说明” 2.获取wsdl文件.使用JDK1.6以上的版本的wsimport命令 a) 例如选中:http://webservice.webxml.com.cn/WebSe ...
- Linux内核OOM机制的详细分析(转)
Linux 内核 有个机制叫OOM killer(Out-Of-Memory killer),该机制会监控那些占用内存过大,尤其是瞬间很快消耗大量内存的进程,为了 防止内存耗尽而内核会把该进程杀掉.典 ...
- 键盘ctrl+shift不能切换输入法
1.首先检查输入法是否被卸载,如没被卸载: 2.使用下面如图方法进行设置
- iOS - Swift 基本语法
前言 Swift 全面支持 Unicode 符号. Swift 中的定义和实现是在同一个单元中的,通常一个 Swift 源代码单文件是以 ".Swift" 结尾的. Swift 不 ...
- c point
a[i] 与 *(a+i) 是等价的. 事实上在计算a[i]的值时,c语言首先将前者转换为后者形式, 而且,通常而言,用指针编写的程序要比用数组下标编写的程序执行速度快,(为什么?) 因此,应该尽量用 ...
- MySQL Server 5.7解压版缺少文件无法启动
如题: 一般认为5.7中mysql目录下 缺少data/mysql/目录,导致无法启动: 解决方案: 重新安装5.6即可: 1.删除5.7中安装的服务: 到mysql\bin目录下运行:mysqld ...
- poj3304Segments(直线与多条线段相交)
链接 枚举两点(端点),循环遍历与直线相交的线段. #include <iostream> #include<cstdio> #include<cstring> # ...
- java文件操作(读流)
try{ InputStream is = new FileInputStream("abc.txt"); InputStreamReader ir = new InputStre ...