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 ...
随机推荐
- Blocks(POJ 3734 矩阵快速幂)
Blocks Input The first line of the input contains an integer T(1≤T≤100), the number of test cases. E ...
- 命令行工具命令 - run包到手机里
命令行工具命令 你完全可以选择不输入以下这些命令,执行这些命令的结果与在 Android Studio 中单击"运行"按钮是一样的. chmod +x gradlew - 此命令只 ...
- Codeforces 540D Bad Luck Island
http://codeforces.com/problemset/problem/540/D 题目大意: 会出石头.剪刀.布的人分别有r,s,p个,他们相互碰到的概率相同,输的人死掉,问最终活下去的人 ...
- Java中一些常用的代码
总结一下最近程序中用到的代码吧,大部分不是自己写的,放到这里,备份一下,以后忘记了来看一下: //正则表达式验证手机号 public static void phoneTest(String phon ...
- bzoj1190
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1190 神题...... F[i][j]表示容量为j*2^i+W第i-1位到第0位的最大价值, ...
- 2014.6.14模拟赛【bzoj1646】[Usaco2007 Open]Catch That Cow 抓住那只牛
Description Farmer John has been informed of the location of a fugitive cow and wants to catch her i ...
- pyqt搜索指定信息 github处找到,谢谢这位朋友的帮助了
def tabunqi(self,text): #第一遍添加之后,不提示,当第二次添加相同的数据时,就提示下 text1=str(text) items = self.downwid ...
- 搭建Android环境
1.相关文件下载: 1.1.Java jdk下载: JDK下载地址 http://www.oracle.com/technetwork/java/javase/downloads/jre7-downl ...
- javascript自定义浏览器右键菜单
javascript自定义浏览器右键菜单 在书上看到document对象还有一个contextmenu事件,但是不知为什么w3school中找不到这个耶... 利用这个特性写了个浏览器的右键菜单, ...
- IIS PHP 配置 问题总结
今天帮助朋友解决一个IIS配置PHP的问题.大概是这样子的. IIS 与 PHP配置好了之后不能訪问,出现例如以下错误: HTTP 错误 500.19 - Internal Server Error ...