Same question from last year. Use dynamic programming.
rics
2010-03-19 15:28:02
there is a very naive algorithm that runs in O(N^6) time. just maintain two indexes in the matrix (O(N^4) time), and determine whether the rectangle defined by them is correct (O(N^2) time).