diff options
Diffstat (limited to 'progs/a294.py')
-rw-r--r-- | progs/a294.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/progs/a294.py b/progs/a294.py new file mode 100644 index 0000000..cafc3e7 --- /dev/null +++ b/progs/a294.py @@ -0,0 +1,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]
\ No newline at end of file |