The maximum sum of the submatrix matrix is ​​NxN and with N-nonzero values, only O (N ^ 2)

Suppose you have N & times; N, where each row has exactly one non-zero element, and each column has exactly one non-zero element (non-zero elements can be either positive or negative). We want to find the submatrix of the maximum amount. How effective can we do this?

The matrix has a dimension of N x N and only N nonzero elements. N is so large that I cannot use the O (N 3 ) algorithm . Does anyone know how to solve this in time O (N 2 ), O (N log N) or some other complicated time complexity?

Thanks!

+4
source share
1 answer

If you want to find the maximum total rectangle, you can do this in O (n ^ 2 log n) using the maximum total rectangle in the sparse matrix described here . This is superior to the Kadane algorithm, which is O (n ^ 3).

+2
source

Source: https://habr.com/ru/post/1525858/


All Articles