Skip to content

Instantly share code, notes, and snippets.

@kangeugine
Created August 9, 2018 02:25
Show Gist options
  • Select an option

  • Save kangeugine/47a308470ef215714b860dafcafd677b to your computer and use it in GitHub Desktop.

Select an option

Save kangeugine/47a308470ef215714b860dafcafd677b to your computer and use it in GitHub Desktop.

Revisions

  1. kangeugine created this gist Aug 9, 2018.
    10 changes: 10 additions & 0 deletions knapsack-dp-example.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    # 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]