|
3 | 3 |
|
4 | 4 | Note that only the integer weights 0-1 knapsack problem is solvable using dynamic programming.
|
5 | 5 | """
|
6 |
| -from __future__ import print_function, division, absolute_import |
7 |
| - |
| 6 | +from typing import Union |
8 | 7 |
|
9 | 8 | def MF_knapsack(i,wt,val,j):
|
10 | 9 | '''
|
@@ -35,7 +34,7 @@ def knapsack(W, wt, val, n):
|
35 | 34 | return dp[n][W], dp
|
36 | 35 |
|
37 | 36 |
|
38 |
| -def knapsack_with_example_solution(W, wt, val): |
| 37 | +def knapsack_with_example_solution(W: int, wt: list, val:list): |
39 | 38 | """
|
40 | 39 | Solves the integer weights knapsack problem returns one of
|
41 | 40 | the several possible optimal subsets.
|
@@ -87,7 +86,7 @@ def knapsack_with_example_solution(W, wt, val):
|
87 | 86 | return optimal_val, example_optional_set
|
88 | 87 |
|
89 | 88 |
|
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): |
91 | 90 | """
|
92 | 91 | Recursively reconstructs one of the optimal subsets given
|
93 | 92 | a filled DP table and the vector of weights
|
|
0 commit comments