Skip to content

Commit

Permalink
Fixed another little thing in 01-knapsack
Browse files Browse the repository at this point in the history
  • Loading branch information
nbro committed Jan 26, 2017
1 parent 3a0cf20 commit dfdd3fd
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions ands/algorithms/dp/zero_one_knapsack.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ def _memoized_01_knapsack_aux(capacity: int, w, v, value: int, m: list) -> int:
if len(w) > 0 and len(v) > 0:

if w[-1] > capacity: # We cannot include the nth item
value = _memoized_01_knapsack_aux(
capacity, w[:-1], v[:-1], value, m)
value = _memoized_01_knapsack_aux(capacity, w[:-1], v[:-1], value, m)
else:
value = max(v[-1] + _memoized_01_knapsack_aux(capacity - w[-1], w[:-1], v[:-1], value, m),
_memoized_01_knapsack_aux(capacity, w[:-1], v[:-1], value, m))
Expand Down

0 comments on commit dfdd3fd

Please sign in to comment.