Algorithm to find the maximum subsequence of an array of positive numbers . Catch : No adjacent elements allowed

前端 未结 13 1126
甜味超标
甜味超标 2020-12-24 04:42

For example, given

A = [1,51,3,1,100,199,3], maxSum = 51 + 1 + 199 = 251.

clearly max(oddIndexSum,evenIndexSum) does not

13条回答
  •  粉色の甜心
    2020-12-24 04:50

    While you used a bunch of fancy words, isn't this basically just a plain old graph problem of the travelling salesman?

    Except in this case you are looking for the most expensive route through the (dense) graph? In this case the vertices are just the numbers themselves, the edges are not directed and have no weight, and all vertices are connected, except to the vertices that had been adjacent to them in the original list?

提交回复
热议问题