Skip to content

Instantly share code, notes, and snippets.

@kangeugine
Created August 9, 2018 02:25
Show Gist options
  • Save kangeugine/47a308470ef215714b860dafcafd677b to your computer and use it in GitHub Desktop.
Save kangeugine/47a308470ef215714b860dafcafd677b to your computer and use it in GitHub Desktop.
# Example
val = [60, 100, 120, 120]
wt = [10, 20, 30, 20]
W = 50
n = len(val)
K = knapSack(W, wt, val, n)
ix = knapSackIndex(W, wt, val, n ,K)
print("Max value:{}, with items:{}".format(K[-1][-1], str(ix)))
# Max value:280, with items:[3, 1, 0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment