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 ...
随机推荐
- Objective-C Http常用API 同步请求与异步请求
开发iOS应用要调用Http接口.获取Http资源,有一套比较成熟的框架ASIHTTPRequest.而我还是比较喜欢使用原始一点的 API,而它跟其他的面向对象语言有许多共通之处.本文分同步请求和异 ...
- Visual studio 内存不足的解决方案(out of memory)
编译Visual Studio项目,如果出现"out of memory "的编译错误,可以进行如下操作,加大应用程序可以使用的内存. 请先备份好系统和设置好系统还原点,大体步骤是 ...
- AngularJS自定义表单验证
<!doctype html> <html ng-app="myApp"> <head> <script src="G:\\So ...
- 使用redis缓存加索引处理数据库百万级并发
使用redis缓存加索引处理数据库百万级并发 前言:事先说明:在实际应用中这种做法设计需要各位读者自己设计,本文只提供一种思想.准备工作:安装后本地数redis服务器,使用mysql数据库,事先插入1 ...
- 变量数据是怎么进ARM中的RAM中?
这篇文章 是从网上复制过来的.觉得不错,分享给大家.原文地址:http://eetrend.com/forum/100028828 ARM的体系结构有很多很多介绍的地方,从其7种模式到CPSR状态寄存 ...
- 使用 ExpandableListView 实现折叠ListView
1:layout/expandablelistview_groups.xml 标题文件 <?xml version="1.0" encoding="utf-8&qu ...
- CentOS下Qt窗口透明效果失效,成黑色背景的问题
一.问题 Linux系统下Qt窗口的透明效果成了黑色,但同样的代码在windows机子上有透明效果,主要是修改系统的配置,仅在centos6.3及其以上版本实验过.其他系统可以相应配置. 二.问题运行 ...
- cf493A Vasya and Football
A. Vasya and Football time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- CCF软考---《有趣的数》
脑子一热报了CCF的软测..但是又觉得好像并没有什么卵用,就当为蓝桥杯预热然后顺便去软件学院玩一玩吧,遇到一个有意思的题: time limits : 1s 问题描述 我们把一个数称为有趣的,当且仅当 ...
- 又一编辑神器-百度编辑器-Ueditor
(Lionden<hsdlionden@gmail.com> 转载说明) 前段时间发表过一篇关于“KindEditor在JSP中使用”的博文.这几天在沈阳东软进行JavaWeb方面的实习工 ...