Largest submatrix with equal no of 1's and 0's

后端 未结 4 1936
抹茶落季
抹茶落季 2020-12-24 09:41

Given a matrix of size mxn containing 0\'s and 1\'s only. I need to find the largest sub-matrix which has equal number of 1\'s and 0\'s in it. Brute force appro

4条回答
  •  时光取名叫无心
    2020-12-24 10:38

    We assume m < n, and we can have an O(M * M * N) algorithm. And if we replace all 0 by -1, we just find the largest submaxtrix whose sum is 0.

    1. Get the sum of segments(i, j) in each row, we define them c1, c2, c3....,cn, we can run O(n) algorithm on it by the algorithm you referenced.
    2. We should do step 1 M * M times to get the largest submaxtrix whose sum is 0, so the complexity is O(M * M * N).

提交回复
热议问题