题目链接:https://www.luogu.org/problemnew/show/SP1805 分析: 我们可以用一个单调栈由低到高来存储它的高度,并用数组对每个高度记录一下它前面(包括它自己)一共有多少个比它高的,可以看做它的左宽. 按顺序考虑每个高度h,如果h大于栈顶元素,则入栈,此时它大于左面全部的元素,并且将它的宽度初始为1. 否则,将栈内元素出栈,直到满足上面的条件.出栈时,我们要将出栈元素对之后问题的影响全部考虑进行处理,才能保证做法的正确性. 对于每个高度,它的作用无非两个:…
--------------------------------------------------- 我就是想学个单调栈然后全网都是个蓝题 --------------------------------------------------- 连接: POJ 洛谷 --------------------------------------------------- (字都在注释上) #include<iostream> #include<stack> #include<c…
题目链接: https://www.luogu.org/problemnew/show/SP1805 http://poj.org/problem?id=2559 思路: ## 单调栈 首先如果所有矩形的高度是单调递增的,即新加入的矩形比上一个高,那么把加进来直至加完,这是我们就把分别每个矩形的高度看做是最大子矩形的高度,分别向左右拓展求得最大面积. 然而矩形的高度不一定是递增的,如果新加入的矩形比上一个小,那么之前这些矩形的高度对于后面的计算就没用了.我们就在这时候把比这个新加的矩形高的部分全…
[题解]Largest Rectangle in a Histogram [SP1805] [POJ2559] [题目描述] 传送: \(Largest\) \(Rectangle\) \(in\) \(a\) \(Histogram\) \([SP1805]\) \([POJ2559]\) 同一水平线上有 \(n\) 个矩形,构成了一个柱状多边形,矩形宽度均为 \(1\),高度不同.如图: 你需要在多边形中框选出一个矩形,使其面积最大,如图阴影部分. [输入] 每组数据包含一个整数 \(n\)…
Largest Rectangle in a Histogram Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19782   Accepted: 6393 Description A histogram is a polygon composed of a sequence of rectangles aligned at a common base line. The rectangles have equal wi…
Description A histogram is a polygon composed of a sequence of rectangles aligned at a common base line. The rectangles have equal widths but may have different heights. For example, the figure on the left shows the histogram that consists of rectang…
Largest Rectangle in a Histogram Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submission(s) : 16   Accepted Submission(s) : 6 Problem Description A histogram is a polygon composed of a sequence of rectangles…
传送门 Description A histogram is a polygon composed of a sequence of rectangles aligned at a common base line. The rectangles have equal widths but may have different heights. For example, the figure on the left shows the histogram that consists of rec…
Largest Rectangle in a Histogram HDU1506 一道DP题: 思路:http://blog.csdn.net/qiqijianglu/article/details/8556852 #include <stdio.h> #include <iostream> using namespace std; ]; ],r[]; int main() { int n,i,j; long long maxx,sum; while(~scanf("%d…
Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18942   Accepted: 6083 Description A histogram is a polygon composed of a sequence of rectangles aligned at a common base line. The rectangles have equal widths but may have different heigh…