Sample Code
dp = [0] * (W + 1)
for weight in weights:
for w in range(W, weight - 1, -1):
dp[w] = max(dp[w], dp[w - weight] + value)
tutorial video :
Easy (Knapsack Basics)
Medium (Classic 0/1 Knapsack)
Sample Code
dp = [0] * (W + 1)
for weight in weights:
for w in range(W, weight - 1, -1):
dp[w] = max(dp[w], dp[w - weight] + value)
tutorial video :
Easy (Knapsack Basics)
Medium (Classic 0/1 Knapsack)
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)