Skip to content

Instantly share code, notes, and snippets.

@zain
Created January 9, 2012 08:39
Show Gist options
  • Save zain/1581976 to your computer and use it in GitHub Desktop.
Save zain/1581976 to your computer and use it in GitHub Desktop.
def heaviest_incr_subseq(seq, weights):
dp = {}
dp[0] = weights[0]
for i in xrange(1, len(seq)):
dp[i] = weights[i]
for j in reversed(xrange(0, i - 1)):
if (dp[j] + weights[i] > dp[i]):
dp[i] = dp[j] + weights[i]
return max(dp.values())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment