+4  A: 

Same question from last year. Use dynamic programming.

rics
A: 

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).

sisis
forget about this, DP is applicable as there is substructure.
sisis