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 ...
随机推荐
- Python 升级
1.到官网下载对于的版本: 2.下载之后并解压出来,编译: tar xf python.xx.xx.tar.xz sudo mkdir /usr/local/python ./configure -- ...
- Gradient Descent 和 Stochastic Gradient Descent(随机梯度下降法)
Gradient Descent(Batch Gradient)也就是梯度下降法是一种常用的的寻找局域最小值的方法.其主要思想就是计算当前位置的梯度,取梯度反方向并结合合适步长使其向最小值移动.通过柯 ...
- Android系统服务-简介
http://blog.csdn.net/chenyafei617/article/details/6577907 Introduction 我们知道Android系统服务挺多的,做程序时经常会用到, ...
- DDUI For Delphi Seattle Directui界面组件
http://www.delphigear.cn/0/11258/go.aspx http://bbs.csdn.net/topics/390285613
- 【Xamarin 开发 IOS --IOS 页面导航概念Segue】
Storyboard里面的几种Segue区别及视图的切换:push,modal,popover,replace和custom 一.视图切换类型介绍在storyboard中,segue有几种不同的类型, ...
- 关于group by
<pre name="code" class="sql">关于group by 排序问题 10g 以前sort group by 需要排序 10g ...
- nodejs教程
http://www.yiibai.com/nodejs/ http://www.runoob.com/nodejs/nodejs-tutorial.html http://www.runoob.co ...
- BZOJ1106: [POI2007]立方体大作战tet
1106: [POI2007]立方体大作战tet Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 419 Solved: 302[Submit][St ...
- Java中一些常用的代码
总结一下最近程序中用到的代码吧,大部分不是自己写的,放到这里,备份一下,以后忘记了来看一下: //正则表达式验证手机号 public static void phoneTest(String phon ...
- 马士兵 Servlet_JSP(3) Servlet和JSP的通信(源代码)
(1)从JSP调用Servlet可用<jsp:forward>,请求信息自动转到Servlet FromJspToServlet.jsp <html> <body ...