Largest Rectangle in a Histogram 杭电1506
题目链接 :http://acm.hdu.edu.cn/showproblem.php?pid=1506

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
4000
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+;
typedef long long ll;
ll arr[N];
int main(){
int n;
while(cin>>n,n){
stack<int >st;
for(int i=;i<=n;i++) scanf("%lld",&arr[i]);
arr[n+]=;
long long ans=;
for(int i=;i<=n+;i++){
if(st.empty()||arr[i]>=arr[st.top()]){
st.push(i);
}
else {
int x=st.top();
while(st.size()&&arr[i]<arr[x]){
st.pop();
if(st.size()){
ans=max(ans,arr[x]*(i-st.top()-));
x=st.top();
}
else ans=max(ans,arr[x]*(i-));
}
st.push(i);
}
}
cout<<ans<<endl;
} return ;
}
Largest Rectangle in a Histogram 杭电1506的更多相关文章
- Largest Rectangle in a Histogram(HDU 1506 动态规划)
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 set+二分
Largest Rectangle in a Histogram Problem Description: A histogram is a polygon composed of a sequenc ...
- uva 1506 Largest Rectangle in a Histogram
Largest Rectangle in a Histogram http://acm.hdu.edu.cn/showproblem.php?pid=1506 Time Limit: 2000/100 ...
- 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: ...
- 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 分类: 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 ...
随机推荐
- CTF_WriteUp_HTTP基本认证(Basic access authentication)
HTTP基本认证 在HTTP中,基本认证(英语:Basic access authentication)是允许http用户代理(如:网页浏览器)在请求时,提供用户名和密码 的一种方式.HTTP基本认证 ...
- [枚举] HDU 2019 Multi-University Training Contest 8 - Calabash and Landlord
Calabash and Landlord Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/ ...
- jquery实现元素的显示和隐藏
这个是指定表格列的隐藏的demo,其余的都大同小异了 $("#account-table tr").find($("#tcNum")).show();//sho ...
- logstash设置从文件读取的重要参数说明及如何强置重新读取
问题描述: 如果运行logstash时从文件读取数据时,就会遇到一个问题,如果读取的目标文件未经修改,而仅修改了conf文件,则即使重新运行logstash,或是执行时使用-r时输出也无法更新. 解决 ...
- c#委托、泛型委托和匿名方法
题外话:别指望看第一遍书就能记住和掌握什么——请看第二遍.第三遍. 本人女猿一枚,2年工作经验,喜欢钻研,喜欢创新,闲暇之余喜欢写写博客,深知自身能力薄弱,如表达错误.不当之处请园友们多多指出,互相交 ...
- 【笔记3-31】Python语言基础-列表list
列表list my_list = [1, 2, 3, 4, 5] 索引index my_list[0] 获取列表长度 len(my_list) 切片 [起始:结束:步长] my_list[1:3:2] ...
- linux service 例子
在 /etc/init.d/ 中创建新文件 #/bin/sh # 检查第一个参数是什么来执行对应动作 case $1 in start) /usr/local/php/bin/php-cgi -b 1 ...
- 15.自动部署web工程
用maven自动部署web工程 在pom.xml中写入以下: <build> <!--最终名称,进入网页时有http://localhost:8080/xxx/--> < ...
- 6.Metasploit生成apk攻击Android实例
Metasploit进阶第四讲 生成Android apk文件 01 msfvenom基本参数 msfvenom介绍 承接上回,staged/unstage payload如何利用? msfven ...
- Spring 中使用 ActiveMQ 笔记
首先需要在 pom.xml 中添加如下两个 jar 包:spring-jms 与 activemq-core,其依赖的 jar 包会自动下载 接着进行相关配置 @Configuration publi ...