summaryrefslogtreecommitdiff
path: root/progs/a669.py
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2024-05-28 10:29:13 +0200
committerSanto Cariotti <santo@dcariotti.me>2024-05-28 10:29:13 +0200
commitf05d888a0b621ca4e99e2b0fb6e23c097006fe41 (patch)
treeeebbb2489144112d3288393e354d19375a0aa088 /progs/a669.py
Init
Diffstat (limited to 'progs/a669.py')
-rw-r--r--progs/a669.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/progs/a669.py b/progs/a669.py
new file mode 100644
index 0000000..8c0d2da
--- /dev/null
+++ b/progs/a669.py
@@ -0,0 +1,18 @@
+def max_sum_increasing_subseq(a, n, index, k):
+ dp = [[0 for i in range(n)]
+ for i in range(n)]
+ for i in range(n):
+ if a[i] > a[0]:
+ dp[0][i] = a[i] + a[0]
+ else:
+ dp[0][i] = a[i]
+ for i in range(1, n):
+ for j in range(n):
+ if a[j] > a[i] and j > i:
+ if dp[i - 1][i] + a[j] > dp[i - 1][j]:
+ dp[i][j] = dp[i - 1][i] + a[j]
+ else:
+ dp[i][j] = dp[i - 1][j]
+ else:
+ dp[i][j] = dp[i - 1][j]
+ return dp[index][k] \ No newline at end of file