Complete the code to initialize the dp array for the unbounded knapsack.
int[] dp = new int[[1] + 1];
The dp array size should be capacity + 1 to store maximum values for all capacities from 0 to capacity.
Complete the code to iterate over all capacities in the unbounded knapsack solution.
for (int w = 1; w <= [1]; w++) {
The loop should run from 1 to capacity to consider all possible weights.
Fix the error in the condition to check if the current item can fit in the knapsack.
if (weights[i] [1] w) {
The item weight must be less than or equal to the current capacity to fit.
Fill both blanks to update dp[w] with the maximum value including the current item.
dp[w] = Math.max(dp[w], dp[w - [1]] + [2]);
Subtract the weight of the current item from w to find the remaining capacity, then add the item's value.
Fill all three blanks to complete the nested loops for unbounded knapsack.
for (int i = 0; i < [1]; i++) { for (int w = [2]; w <= [3]; w++) {
The outer loop runs over all items, the inner loop runs from 1 to capacity to consider all weights.
