β Back
βΎοΈ Knapsack Kingdom - Infinite
Unlimited copies of each item! β’ Maximize with repetition
Capacity:
π² Random Items
βΆ Run Unbounded DP
π Items (Unlimited Supply)
π
Capacity:
8
π 1D DP Table (dp[w] = max value for capacity w)
π Unbounded Knapsack
dp[w] = max(dp[w], val[i] + dp[w - wt[i]])
For each capacity w, try ALL items
Key: dp[w - wt[i]] (same row!)
Items Used
0
0/1 Answer
-
Unbounded Max
?
π Optimal Selection
Run DP to see...
π‘ Key Difference
0/1:
dp[i-1][w - wt] (previous row)
Unbounded:
dp[w - wt] (same row!)
This allows using same item multiple times!