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 ...
随机推荐
- Prism 源码解读1-Bootstrapper和Region的创建
介绍 之前也研究过Prism框架但是一直没有深入理解,现在项目上想把一个Winform的桌面应用程序改造成WPF程序,同时我希望程序是可测试可维护架构良好的,Prism的这些设计理念正好符合我的需求, ...
- [状态压缩,折半搜索] 2019牛客暑期多校训练营(第九场)Knapsack Cryptosystem
链接:https://ac.nowcoder.com/acm/contest/889/D来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 262144K,其他语言52428 ...
- Linux时间和现实时间不同步解决方案
输入三条命令 yum install ntpdate -y ntpdate tiger.sina.com.cnping tiger.sina.com.cn 然后输入date检查时间是否已经同步
- TensorFlow系列专题(八):七步带你实现RNN循环神经网络小示例
欢迎大家关注我们的网站和系列教程:http://panchuang.net/ ,学习更多的机器学习.深度学习的知识! [前言]:在前面的内容里,我们已经学习了循环神经网络的基本结构和运算过程,这一小节 ...
- 模块 psutil 系统信息获取
psutil模块介绍 psutil是一个开源切跨平台的库,其提供了便利的函数用来获取才做系统的信息,比如CPU,内存,磁盘,网络等.此外,psutil还可以用来进行进程管理,包括判断进程是否存在.获取 ...
- [codevs1049]棋盘染色<迭代深搜>
题目链接:http://codevs.cn/problem/1049/ 昨天的测试题里没有打出那可爱的迭代深搜,所以今天就来练一练. 这道题其实我看着有点懵,拿着题我就这状态↓ 然后我偷偷瞄了一眼hz ...
- Python——matplotlib基础绘图函数示例
1. 2.饼图 (1) import matplotlib.pyplot as plt labels='frogs','hogs','dogs','logs'% sizes=[15,30,45,10] ...
- 实战级Stand-Alone Self-Attention in CV,快加入到你的trick包吧 | NeurIPS 2019
论文提出stand-alone self-attention layer,并且构建了full attention model,验证了content-based的相互关系能够作为视觉模型特征提取的主要基 ...
- win10 系统中vscode 的终端 shell 设置
今天,打算开始搞一个个人博客小项目. 主力台式电脑在实验室,于是重新配了一下自己的小破笔记本.系统是之前自己捣鼓的 win10 .在打开终端调试 node 时,发现报了这么一个错. 我刚开始以为是自己 ...
- override 重写
//override:子类继承父类,子类重写父类的方法 public class override { public static void main(String[] args) { horse h ...