avatar
l*n
1
Give a square matrix with n x n cells. Each cell is either filled with a
black pixel or a white pixel. Design an algorithm to find the maximum
subsquare such that all four borders are filled with black pixels;
Note: it is not the same as the wellknown question for the max sub-matrix
with all filled 0/1.... so the DP equation does not apply here..
Any good approach better than brute force?
avatar
p*2
2
你老怎么也上来做题了?夫人吗。
avatar
p*2
3
你说的bruteforce是什么复杂度? N^3?
avatar
l*a
4
牛人不都是拿着18W的offer然后准备找25W的?

【在 p*****2 的大作中提到】
: 你老怎么也上来做题了?夫人吗。
avatar
l*a
5
brute force应该是N4

【在 p*****2 的大作中提到】
: 你说的bruteforce是什么复杂度? N^3?
avatar
l*n
6
二爷您还在这坐镇呢:) yes, this is LD
N^3 is the minimum I can think , with some auxiliary space. The most naive
brute force is actually N^4..
等待二爷高招
avatar
p*2
7

感觉N^3是不是就行了?

【在 l*****n 的大作中提到】
: 二爷您还在这坐镇呢:) yes, this is LD
: N^3 is the minimum I can think , with some auxiliary space. The most naive
: brute force is actually N^4..
: 等待二爷高招

avatar
l*a
8
Copied the answer from careercup150. I can hardly understand the algorithm
which claimed to have complexity O^2.
Assumption: Square is of size NxN.
This algorithm does the following:
1. Iterate through every (full) column from left to right.
2. At each (full) column (call this currentColumn), look at the subcolumns (
from biggest to smallest).
3. At each subcolumn, see if you can form a square with the subcolumn as the
left side. If so, update currentMaxSize and go to the next (full) column.
4. If N - currentColumn <= currentMaxSize, then break completely. We've
found the largest square possible. Why? At each column, we're trying to
create a square with that column as the left side. The largest such square
we could possibly create is N - currentColumn. Thus, if N-currentColumn <=
currentMaxSize, then we have no need to proceed.
Time complexity: O(N^2).
avatar
l*c
10
N x N
N**2 easily
avatar
f*n
11
预处理+RMQ O(N^2)
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。