hdu 1507 Largest Rectangle in a Histogram 动态规划计算最大面积
记录动态规划dpl,dpr,分辨记录i左面的比i大的,右面比i大的,然后(dpr[i]-dpl[i]+1)*h[i]得出长度
动态转移方程while(temp>1 && h[temp-1]>=h[i]) temp=dpl[temp-1]
/*************************************************************************> File Name: hdu1506.cpp> Author: yang> Mail:826123027@qq.com > Created Time: 2014年08月24日 星期日 23:41:16************************************************************************/#include<iostream>
#include<stdio.h>
#include<memory.h>
using namespace std;
#define N 100005
int main(){int dpl[N],dpr[N];long long h[N];int n;while(scanf("%d",&n),n){for(int i=1;i<=n;i++)scanf("%lld",&h[i]);dpl[1]=1;int temp;for(int i=2;i<=n;i++){temp=i;while(temp>1 && h[temp-1]>=h[i]) temp=dpl[temp-1];dpl[i]=temp;}dpr[n]=n;for(int i=n-1;i>=1;i--){temp=i;while(temp<n && h[i]<=h[temp+1]) temp=dpr[temp+1]; dpr[i]=temp;}long long sum,ans=0;for(int i=1;i<=n;i++){
// cout<<dpl[i]<<" "<<dpr[i]<<endl;sum=(dpr[i]-dpl[i]+1)*h[i];
// cout<<"sum:"<<sum<<endl;if(sum>ans) ans=sum;}cout<<ans<<endl;}
}
hdu 1507 Largest Rectangle in a Histogram 动态规划计算最大面积相关推荐
- hdu 1506 Largest Rectangle in a Histogram 最大矩形
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1506 Largest Rectangle in a Histogram Time Limit: 20 ...
- HDU 1506 Largest Rectangle in a Histogram(dp、单调栈)
你是不是飘了?骚年! Problem Description A histogram is a polygon composed of a sequence of rectangles aligned ...
- HDU 1506 Largest Rectangle in a Histogram
这个问题姑且也叫做最大子矩阵吧 给一个树状图,求一个最大面积的子矩阵 思路是这样的,对于每个单位矩阵,求出左边连续不比它低的矩阵的下标,放在l数组里 同样,再求出右边连续的不比它低的矩阵的下标 这样, ...
- *【HDU - 1506】【POJ - 2559】Largest Rectangle in a Histogram(单调栈或动态规划)
题干: Description A histogram is a polygon composed of a sequence of rectangles aligned at a common ba ...
- Largest Rectangle in a Histogram (动态规划+奇思妙想单调栈)求最大矩状图面积
感觉动态规划都是玄妙的很,思维题吧(单调栈思维) 题解:让求最大矩形面积,宽为1,暴力超时 可以发现 当第i-1个比第i个高的时候 比第i-1个高的所有也一定比第i个高 于是可以用到动态规划的 ...
- Largest Rectangle in a Histogram HDU - 1506 解题思路 单调栈
原题目 Problem Description A histogram is a polygon composed of a sequence of rectangles aligned at a c ...
- poj 2559 Largest Rectangle in a Histogram 栈
// poj 2559 Largest Rectangle in a Histogram 栈 // // n个矩形排在一块,不同的高度,让你求最大的矩形的面积(矩形紧挨在一起) // // 这道题用的 ...
- 【单调栈】Largest Rectangle in a Histogram(luogu-SP1805/poj 2559)
Largest Rectangle in a Histogram luogu-SP1805 poj 2559 题目大意: 有n个并排的矩阵,高度为aia_iai,宽度为1,现在让求包含于这些矩阵的并 ...
- 【Python CheckiO 题解】Largest Rectangle in a Histogram
CheckiO 是面向初学者和高级程序员的编码游戏,使用 Python 和 JavaScript 解决棘手的挑战和有趣的任务,从而提高你的编码技能,本博客主要记录自己用 Python 在闯关时的做题思 ...
- HDU 1506 解题报告 Largest Rectangle in a Histogram (单调栈)
看题传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1506 题意比较明显,就是找以某一个矩形为高的最大的矩形.这个题可以用单调栈来求解,需要注意的是如果从 ...
最新文章
- The transaction log for database 'tempdb' is full due to 'ACTIVE_TRANSACTION'
- 慕课乐学python编程题_中国大学MOOC的APP(慕课)2020Python编程基础题目及答案
- JAVA Spring Cloud 注册中心 Eureka 相关配置
- NHibernate之旅(10):探索父子(一对多)关联查询
- Cube painting UVA - 253
- 用c语言批量删除指定文件夹,C语言删除文件夹下所有代码的注释for Mac
- 成功解决OSError: [Errno 28] No space left on device
- html5 canvas 版 hello world! 暨haXe简介
- 微软 MS Learn 上线 Blazor 入门教程
- 【redis】Redis简介
- CNN破解简单验证码(Tensorflow实现)
- Apache服务器全局配置之服务器标识配置篇
- Unity推出2D工具:不再只是3D引擎
- 如何通过“限制管理权限”来保护您的企业?
- vue-cnode使用vue重构cnode社区
- 中环混改尚存变数 高调的TCL要上演“资本魔输”?
- 如何使用myabtisPlust将查询出的数据封装给vo对象
- 木子案正判后的故事发展(猜想)
- 微信读书产品体验报告
- Android UI简单美化