由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 算法--一个MXN matrix (0's and 1's)内求最大 rectangle(1's)
相关主题
Maximal Rectangle如果不要求是Rectangle就要简单得多google 面试题
leetcode一道题请教大家一道Google的题目
求Leetcode OJ Maximal Rectangle的n^2解法请问一道面试题
有用java过Maximal Rectangle的judge large的吗?请教一个Axis-Aligned Rectangles的算法
Maximal Rectangle O(mn) 解法 非 histogram求一道 面世题 的解答思路
我也来问问LC的Maximal Rectangle求overlap的rectagales
Maximal Rectangle TLE是指代码正确,但不是最优吗?问道G题(2)
问一道G家面试题请教一道careercup 150上的题
相关话题的讨论汇总
话题: matrix话题: rectangle话题: construct话题: entry话题: sub
进入JobHunting版参与讨论
1 (共1页)
i**9
发帖数: 351
1
一道老题,求最大square 可以用 DP
http://geeksforgeeks.org/?p=6257
Let the given binary matrix be M[R][C]. The idea of the algorithm is to
construct an auxiliary size matrix S[][] in which each entry S[i][j]
represents size of the square sub-matrix with all 1s including M[i][j] and
M[i][j] is the rightmost and bottommost entry in sub-matrix.
1) Construct a sum matrix S[R][C] for the given M[R][C].
a) Copy first row and first columns as it is from M[][] to S[][]
b) For other entries, use following expressions to construct S[][]
If M[i][j] is 1 then
S[i][j] = min(S[i][j-1], S[i-1][j], S[i-1][j-1]) + 1
Else /*If M[i][j] is 0*/
S[i][j] = 0
2) Find the maximum entry in S[R][C]
3) Using the value and coordinates of maximum entry in S[i], print
sub-matrix of M[][]
求最大的rectangle有什么解法?
i**********e
发帖数: 1145
2
See the maximal rectangle solution explained here using step-wise
improvement:
http://www.drdobbs.com/184410529
http://www.seas.gwu.edu/~simhaweb/cs151/lectures/module6/module (search for maximal rectangle)
The optimal solution is O(M*N) (ie, the size of the rectangle). This problem
is actually very much related to this problem "Largest Rectangle in a
Histogram", which can be solved efficiently in O(N) time.
http://www.informatik.uni-ulm.de/acm/Locals/2003/html/judge.htm
Basically, the easiest way to solve this is using a stack to exploit the
special structure.
一些常见面试题的答案与总结 -
http://www.ihas1337code.com
i**9
发帖数: 351
3
Thanks!

(search for maximal rectangle)
problem

【在 i**********e 的大作中提到】
: See the maximal rectangle solution explained here using step-wise
: improvement:
: http://www.drdobbs.com/184410529
: http://www.seas.gwu.edu/~simhaweb/cs151/lectures/module6/module (search for maximal rectangle)
: The optimal solution is O(M*N) (ie, the size of the rectangle). This problem
: is actually very much related to this problem "Largest Rectangle in a
: Histogram", which can be solved efficiently in O(N) time.
: http://www.informatik.uni-ulm.de/acm/Locals/2003/html/judge.htm
: Basically, the easiest way to solve this is using a stack to exploit the
: special structure.

1 (共1页)
进入JobHunting版参与讨论
相关主题
请教一道careercup 150上的题Maximal Rectangle O(mn) 解法 非 histogram
问个算法题我也来问问LC的Maximal Rectangle
顺时针打印MxN矩阵的简洁递归解法Maximal Rectangle TLE是指代码正确,但不是最优吗?
twitter 一题问一道G家面试题
Maximal Rectangle如果不要求是Rectangle就要简单得多google 面试题
leetcode一道题请教大家一道Google的题目
求Leetcode OJ Maximal Rectangle的n^2解法请问一道面试题
有用java过Maximal Rectangle的judge large的吗?请教一个Axis-Aligned Rectangles的算法
相关话题的讨论汇总
话题: matrix话题: rectangle话题: construct话题: entry话题: sub