no need to pass W, it's global.

This commit is contained in:
onyx-and-iris 2024-01-15 18:28:16 +00:00
parent ec899f2a73
commit 85481bd3d3

View File

@ -18,7 +18,7 @@ class Item:
weight: int weight: int
def dynamic(W, items, n): def dynamic(items, n):
# create table and zero fill it (required for calculations) # create table and zero fill it (required for calculations)
table = [[0 for _ in range(W + 1)] for _ in range(n + 1)] table = [[0 for _ in range(W + 1)] for _ in range(n + 1)]
@ -53,6 +53,6 @@ def format_and_print(table):
items = [Item("Guitar", 1500, 1), Item("Stereo", 3000, 4), Item("Laptop", 2000, 3)] items = [Item("Guitar", 1500, 1), Item("Stereo", 3000, 4), Item("Laptop", 2000, 3)]
W = 4 W = 4
greatest_value = dynamic(W, items, len(items)) greatest_value = dynamic(items, len(items))
print(greatest_value) print(greatest_value)