How can I find the maximum sum of a sub-sequence using dynamic programming?

前端 未结 3 853
陌清茗
陌清茗 2020-12-20 15:56

I\'m re-reading Skiena\'s Algorithm Design Manual to catch up on some stuff I\'ve forgotten since school, and I\'m a little baffled by his descriptions of Dynamic Programmin

3条回答
  •  粉色の甜心
    2020-12-20 16:29

    There is a solution like, first sort the array in to some auxiliary memory, then apply Longest Common Sub-Sequence method to the original array and the sorted array, with sum(not the length) of common sub-sequence in the 2 arrays as the entry into the table (Memoization). This can also solve the problem

    Total running time is O(nlogn)+O(n^2) => O(n^2) Space is O(n) + O(n^2) => O(n^2)

    This is not a good solution when memory comes into picture. This is just to give a glimpse on how problems can be reduced to one another.

提交回复
热议问题