Largest Rectangle in a Histogram(HDU 1506 动态规划)
Largest Rectangle in a Histogram
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 15189 Accepted Submission(s): 4408

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.
0
#include <stdio.h>
#define Max 100005
__int64 dpl[Max],dpr[Max],h[Max];
int main()
{
__int64 n,k,m;
int i,j;
freopen("in.txt","r",stdin);
while(scanf("%I64d",&n)!=EOF)
{
if(n==)
break;
m=;
for(i=;i<=n;i++)
{
scanf("%I64d",&h[i]);
dpr[i]=dpl[i]=i;
}
h[n+]=h[]=;
for(i=n;i>=;i--)
{
while(h[dpr[i]+]>=h[i])
dpr[i]=dpr[dpr[i]+];
}
for(i=;i<=n;i++)
{
while(h[dpl[i]-]>=h[i])
dpl[i]=dpl[dpl[i]-];
}
for(i=;i<=n;i++)
{
k=(dpr[i]-dpl[i]+)*h[i];
if(m<k) m=k;
}
printf("%I64d\n",m);
}
return ;
}
Largest Rectangle in a Histogram(HDU 1506 动态规划)的更多相关文章
- Largest Rectangle in a Histogram HDU - 1506 (单调栈)
A histogram is a polygon composed of a sequence of rectangles aligned at a common base line. The rec ...
- Day8 - C - Largest Rectangle in a Histogram HDU - 1506
A histogram is a polygon composed of a sequence of rectangles aligned at a common base line. The rec ...
- V - Largest Rectangle in a Histogram HDU - 1506
两种思路: 1 单调栈:维护一个单调非递减栈,当栈为空或者当前元素大于等于栈顶元素时就入栈,当前元素小于栈顶元素时就出栈,出栈的同时计算当前值,当前值所包含的区间范围为从当前栈顶元素到当前元素i的距离 ...
- 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 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——T 1506 Largest Rectangle in a Histogram|| POJ——T 2559 Largest Rectangle in a Histogram
http://acm.hdu.edu.cn/showproblem.php?pid=1506 || http://poj.org/problem?id=2559 Time Limit: 2000/1 ...
- HDU 1506 Largest Rectangle in a Histogram(区间DP)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=1506 题目: Largest Rectangle in a Histogram Time Limit: ...
- HDU 1506 Largest Rectangle in a Histogram(DP)
Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
随机推荐
- Hibernate学习笔记--使用ThreadLocal
参考资料: http://blog.sina.com.cn/s/blog_7ffb8dd5010146i3.html http://lavasoft.blog.51cto.com/62575/5192 ...
- MTKdroidToolsV2.53 MTK安卓提取线刷资料的工具 使用教程
备份的时候需插入1G以上内存卡,并确保机器电量充足. 机器需要root才能备份. 最新版本 支持大部分机型 一键root
- [转]RegOpenKeyEx函数失败的问题
在使用这个函数RegOpenKeyEx的时候,老是执行不成功,函数本身返回2,GetLastError返回0.在CSDN上查阅资料说是返回2的原因是注册表中对应路径不存在,可是我电脑中注册表那个键值明 ...
- IntelliJ IDEA: maven & jetty 开发 java web
之前使用eclipse + maven + jetty开发java web应用,本着no zuo no gain的想法, 折腾了一下Intellj idea下开发环境的搭建,顺带学习了maven re ...
- iptables 顺序
-A INPUT -s 115.236.6.6/32 -p udp -m udp --dport 111 -j ACCEPT -A INPUT -s 10.175.197.98/32 -p udp - ...
- 只允许指定的ip访问本机的指定端口22:
只允许指定的ip访问本机的指定端口22: 允许的的ip:192.168.1.123, 192.168.1.124, 192.168.1.100,其他ip都禁止访问. 切换到root用户 1.在tcp协 ...
- AS3给显示对象加边框
给显示对象加边框,可以有以下三种方法1.根据相交路径的缠绕规则的奇偶规则法(使用奇偶缠绕规则时,任何相交路径都交替使用开放填充与闭合填充.如果使用同一填充绘制的两个正方形相交,则不会填充相交的区域.通 ...
- 编程:C#调用Python模块
当下,C#与Python都是比较热门的计算机编程语言,他们各有优缺点,如果能让他们互相配合工作,那是多么美好的事情,今天我来讲解一下如何利用C#来调用Python. 如果让C#支持调用Python模块 ...
- Android自定义ListView的Item无法响应OnItemClick的解决办法
转: 如果你的自定义ListViewItem中有Button或者Checkable的子类控件的话,那么默认focus是交给了子控件,而ListView的Item能被选中的基础是它能获取Focus,也 ...
- QA笑话----杂思
QA工程师走进酒吧,要了一杯啤酒,要了0杯啤酒,要了999999999杯啤酒,要了一只蜥蜴,要了-1杯啤酒,要了一个sfdeljknesv,酒保从容应对,QA工程师 很满意.接下来,一名顾客来到了同一 ...