summaryrefslogtreecommitdiff
path: root/progs/a294.py
blob: cafc3e71036a35cec427cd183e7e26d840f1b80b (plain)
1
2
3
4
5
6
7
8
9
10
11
def max_sum_subseq(A):
    n = len(A)
    if n == 1:
        return A[0]
    look_up = [None] * n
    look_up[0] = A[0]
    look_up[1] = max(A[0], A[1])
    for i in range(2, n):
        look_up[i] = max(look_up[i - 1], look_up[i - 2] + A[i])
        look_up[i] = max(look_up[i], A[i])
    return look_up[n - 1]