Algorithm to find the maximum sum in a sequence of overlapping intervals

前端 未结 6 912
南旧
南旧 2020-11-30 19:33

The problem I am trying to solve has a list of intervals on the number line, each with a pre-defined score. I need to return the maximum possible total score.

The c

6条回答
  •  离开以前
    2020-11-30 20:31

    I think we can use this recursion...

    S[i] denotes the score of each interval
    Interval[i] denotes all the intervals

    ResMax[i] = max(ResMax[i-1] + S[i] //if i is included
               ,max(R[i-1],S[i]) 
             )
    

    I am not checked thoroughly but it should work i beleive.

提交回复
热议问题