Unbounded Knapsack
Given a list of items with weight w[i]
and value v[i]
, what's the maximum value you can get given a knapsack with capacity C
, i.e. it can hold items with at most weight C
in total. You can pick each item unlimited times.
Basic Version
Algorithm
Let dp[i + 1][c]
be the maximum value we can get using the first i + 1
items (index from 0
to i
).
Implementation
Optimized Version
Algorithm
We can examine the relationship between dp[i + 1][c]
and dp[i + 1][c - w[i]]
.
So we have
Implementation
Space Optimization
Problems
Last updated