讨论一下careercup上的一道题,找周边全是1的最大子方阵# JobHunting - 待字闺中
A*r
1 楼
原题如下:
Imagine you have a square matrix, where each cell is filled with either
black or white. Design an algorithm to find the maximum subsquare such that
a ll four borders are filled with black pixels.
http://careercup.com/question?id=2445
大家都知道这是那道找全部为1的最大子方阵的变形(用DP可以达到O(N^2)),可是这道
题却不太能用那道题的方法,从optimal subproblem 无法得到下一个最优解。
CareerCup上给出了一种答案,也就是找出每一个可能的子方阵,然后测试它的四个边
是否满足条件。。这个首先不是DP, 另外他claim算法复杂度是O(N^2), 可是我怎么看
着像O(N^3),因为每找出一个子方阵,需要O(N^2), 但是对每一次方阵进行测试,也是
需要最坏O(N)的,请大家讨论讨论。。
给个例子
1 1 1 1 1
Imagine you have a square matrix, where each cell is filled with either
black or white. Design an algorithm to find the maximum subsquare such that
a ll four borders are filled with black pixels.
http://careercup.com/question?id=2445
大家都知道这是那道找全部为1的最大子方阵的变形(用DP可以达到O(N^2)),可是这道
题却不太能用那道题的方法,从optimal subproblem 无法得到下一个最优解。
CareerCup上给出了一种答案,也就是找出每一个可能的子方阵,然后测试它的四个边
是否满足条件。。这个首先不是DP, 另外他claim算法复杂度是O(N^2), 可是我怎么看
着像O(N^3),因为每找出一个子方阵,需要O(N^2), 但是对每一次方阵进行测试,也是
需要最坏O(N)的,请大家讨论讨论。。
给个例子
1 1 1 1 1