Skip to content

Commit 43fefa1

Browse files
function for the knapsack problem which returns one of the optimal subsets
1 parent 85b9c59 commit 43fefa1

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

dynamic_programming/knapsack.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
44
Note that only the integer weights 0-1 knapsack problem is solvable using dynamic programming.
55
"""
6-
from __future__ import print_function, division, absolute_import
7-
6+
from typing import Union
87

98
def MF_knapsack(i,wt,val,j):
109
'''
@@ -35,7 +34,7 @@ def knapsack(W, wt, val, n):
3534
return dp[n][W], dp
3635

3736

38-
def knapsack_with_example_solution(W, wt, val):
37+
def knapsack_with_example_solution(W: int, wt: list, val:list):
3938
"""
4039
Solves the integer weights knapsack problem returns one of
4140
the several possible optimal subsets.
@@ -87,7 +86,7 @@ def knapsack_with_example_solution(W, wt, val):
8786
return optimal_val, example_optional_set
8887

8988

90-
def _construct_solution(dp, wt, i, j, optimal_set):
89+
def _construct_solution(dp:list, wt:list, i:int, j:int, optimal_set:set):
9190
"""
9291
Recursively reconstructs one of the optimal subsets given
9392
a filled DP table and the vector of weights

0 commit comments

Comments
 (0)