hdu 1506 Largest Rectangle in a Histogram ((dp求最大子矩阵))
# include <stdio.h>
# include <algorithm>
# include <iostream>
# include <math.h>
using namespace std;
__int64 a[100010],l[100010],r[100010];///l[i]左边连续大于等于a[i]的下标,r[i]右边连续大于等于a[i]的下标,所以对于a[i]的矩形面积为(l[i]-r[i]+1)*a[i];
int main()
{
__int64 maxn;
int i,n;
while(~scanf("%d",&n),n)
{
for(i=1;i<=n;i++)
{
scanf("%I64d",&a[i]);
l[i]=r[i]=i;
}
for(i=2;i<=n;i++)
{
while(l[i]>1&&a[l[i]-1]>=a[i])
l[i]=l[l[i]-1];
} for(i=n-1;i>=1;i--)
{
while(r[i]<n&&a[r[i]+1]>=a[i])
r[i]=r[r[i]+1];
}
maxn=-1;
for(i=1;i<=n;i++)
{
if(a[i]*(r[i]-l[i]+1)>maxn)
maxn=a[i]*(r[i]-l[i]+1);
}
printf("%I64d\n",maxn);
}
return 0;
}
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左右处理边界的矩形问题)
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 ...
- HDU -1506 Largest Rectangle in a Histogram&&51nod 1158 全是1的最大子矩阵 (单调栈)
单调栈和队列讲解:传送门 HDU -1506题意: 就是给你一些矩形的高度,让你统计由这些矩形构成的那个矩形面积最大 如上图所示,如果题目给出的全部是递增的,那么就可以用贪心来解决 从左向右依次让每一 ...
随机推荐
- 图片压缩优化kraken
https://kraken.io/web-interface 测试过,可以节省10%左右的大小,图片清晰度不受影响.
- 分享一段css代码学到的js知识
[].forEach.call($$('*'),function(val){ val.style.outline = '1px solid #'+(~~(Math.random()*(1<< ...
- Checkpoint & cache & persist
checkpoint checkpoint(检查点)是Spark为了避免长链路,大计算量的Rdd不可用时,需要长时间恢复而引入的.主要就是将通过大量计算而获得的这类Rdd的数据直接持久化到外部可靠的存 ...
- Python datetime time 等时间 日期 之间的计算和相互转化
from datetime import datetime, date, timedelta, timezone from time import time, ctime, localtime, st ...
- 【2017 Multi-University Training Contest - Team 5】Rikka with Competition
[Link]: [Description] [Solution] 把所有人的能力从大到小排; 能力最大的肯定可能拿冠军; 然后一个一个地往后扫描; 一旦出现a[i-1]-a[i]>k; 则说明从 ...
- VS:"64位调试操作花费的时间比预期要长"的一解决途径
解决的方法之中的一个: 在命令提示符那里打入例如以下命令: netsh winsock reset catalog netsh int ip reset reset.log hit 重新启动电脑后,就 ...
- Matlab piecelin
function v = piecelin(x,y,u) %PIECELIN Piecewise linear interpolation. % v = piecelin(x,y,u) finds t ...
- Linux 获取上个月的第一秒和上个月的最后一秒
因为写脚本需求须要获得上个月的第一秒和上个月的最后一秒,查阅了相关资料,并通过自己实践.找到了以下这样的方法能满足要求.在此备注,若有其它好的方法.请留言.本人将不胜感激. 获取上个月的第一秒: da ...
- 理性分析 C++(-O2) 和 JS 的性能差距
laptop: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz.. Test1: 最后一行:时间(ms) #pragma GCC optimize("O2& ...
- Filebeat之input和output(包含Elasticsearch Output 、Logstash Output、 Redis Output、 File Output和 Console Output)
前提博客 https://i.cnblogs.com/posts?categoryid=972313 Filebeat啊,根据input来监控数据,根据output来使用数据!!! Filebeat的 ...