how to find the maximum L sum in a matrix?

陌路散爱 提交于 2019-12-12 01:10:03

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/4497263/how-to-find-the-maximum-l-sum-in-a-matrix

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!