0

here is another dynamic programming problem that find the maximum L(chess horse - 4 item) sum in the given matrix (m x n)

For example :

1 2 3

4 5 6

7 8 9

L : (1,2,3,6), (1,4,5,6), (1,2,5,8), (4,5,6,9) ...

and the biggest sum is sum(L) = sum(7,8,9,6) = 30

what is the O(complexity) of the optimal solution ?

it looks like this problem (submatrix with maximum sum)

  1. Say all items are positive

  2. Both positive and negative

Any ideas are welcome!

Community
  • 1
  • 1

1 Answers1

5

If your L is constant size (4 elements, as you say), just compute its sum over all < n*m positions and find the maximum one. Repeat for the 8 different orientations you could have. That's O(nm) overall.

Keith Randall
  • 22,985
  • 2
  • 35
  • 54