File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed
Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change 55 https://en.wikipedia.org/wiki/Knapsack_problem
66"""
77
8- from functools import lru_cache
8+ from functools import cache
99
1010
1111def knapsack (
@@ -47,7 +47,7 @@ def knapsack(
4747 if method == "dp" :
4848 return _knapsack_dp (capacity , weights , values , allow_repetition )
4949
50- @lru_cache ( maxsize = None )
50+ @cache
5151 def recur (cap : int , idx : int ) -> int :
5252 if idx == 0 or cap == 0 :
5353 return 0
@@ -64,7 +64,10 @@ def recur(cap: int, idx: int) -> int:
6464
6565
6666def _knapsack_dp (
67- capacity : int , weights : list [int ], values : list [int ], allow_repetition : bool
67+ capacity : int ,
68+ weights : list [int ],
69+ values : list [int ],
70+ allow_repetition : bool ,
6871) -> int :
6972 """Iterative dynamic programming version of the knapsack problem."""
7073 n = len (weights )
You can’t perform that action at this time.
0 commit comments