For each item i and capacity w, you have two choices:
1. Skip item i: Keep the best value from items 1 to i−1 with the same capacity. That's dp[i−1][w].
2. Take item i: Add vi to the best value from items 1 to i−1 with reduced capacity w−wi. That's dp[i−1][w−wi]+vi. You can only take item i if it fits: wi≤w. The transition (the formula to compute each state) is: dp[i][w]=max(dp[i−1][w],dp[i−1][w−wi]+vi) if wi≤w, else dp[i][w]=dp[i−1][w].