最大化直方图下的矩形区域 [英] Maximize the rectangular area under Histogram
问题描述
我有整型高度和宽度不变1.我想在直方图最大限度的矩形区域的直方图。 例如:
I have a histogram with integer heights and constant width 1. I want to maximize the rectangular area under a histogram. e.g.:
_
| |
| |_
| |
| |_
| |
对此的答案是6,3 * 2,使用col1和col2的。
The answer for this would be 6, 3 * 2, using col1 and col2.
为O(n ^ 2)蛮力我很清楚,我想为O(n log n)的算法。我试图想沿着最大提高子澳线动态规划(N log n)的算法中,但我不会前进。我应该使用分而治之算法?
O(n^2) brute force is clear to me, I would like an O(n log n) algorithm. I'm trying to think dynamic programming along the lines of maximum increasing subsequence O(n log n) algo, but am not going forward. Should I use divide and conquer algorithm?
PS:人们有足够的信誉被要求取下分而治之的标签,如果没有这样的解决方案
PS: People with enough reputation are requested to remove the divide-and-conquer tag if there is no such solution.
在姆欧的意见:我的意思是最大的矩形适合完全的区域。 (感谢j_random_hacker澄清:))。
After mho's comments: I mean the area of largest rectangle that fits entirely. (Thanks j_random_hacker for clarifying :) ).
推荐答案
您有很多的解决方案的此处,无论为O(n log n)的
和 O(N)
。
You have a lot of solutions here, both O(n log n)
and O(n)
.
这篇关于最大化直方图下的矩形区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!