简体   繁体   English

找到一个子矩阵,其最大可能总和为O(n ^ 2)

[英]Finding a submatrix with the maximum possible sum in O(n^2)

I'm trying to write a program in Java that when given an MxN matrix it will find the (contiguous) submatrix with the biggest sum of numbers. 我正在尝试用Java编写一个程序,当给定一个MxN矩阵时,它会找到具有最大数字总和的(连续的)子矩阵。 The program then needs to return the top left corner coordinates of the submatrix and the bottom right corner coordinates. 然后程序需要返回子矩阵的左上角坐标和右下角坐标。 The matrix can include negative numbers and both the matrix and submatrix don't need to be square. 矩阵可以包括负数,矩阵和子矩阵都不需要是正方形。

I saw that this was discussed here: Getting the submatrix with maximum sum? 我在这里讨论过这个问题: 获得最大总和的子矩阵? and the solution there seems to be O(n^3). 并且那里的解决方案似乎是O(n ^ 3)。 A friend of mine said that they had once managed to solve this problem in O(n^2). 我的一个朋友说他们曾经设法在O(n ^ 2)中解决了这个问题。 Also suggested here. 这里也建议 Is that possible? 那可能吗?

Is there any available code out there that solves this problem in the most efficient way? 有没有可用的代码以最有效的方式解决这个问题?

You (most likely) can't solve your problem in O(n^2) , at least no such algorithm is known. 你(很有可能)无法在O(n^2)解决你的问题,至少不知道这样的算法。 The optimal solution has sub-cubic complexity, but it's very hard to implement and probably slower in practice. 最优解决方案具有亚立方复杂性,但实现起来非常困难,实际上可能更慢。 You can read a paper about it here . 你可以在这里阅读一篇关于它的论文。

The usual algorithm used is the O(n^3) one referenced in the question you found. 使用的常用算法是您找到的问题中引用的O(n^3)

(S)他是你的朋友..所以请问他/她,并与我们分享:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM