Complete the code to initialize the DP array for the unbounded knapsack problem.
int[] dp = new int[[1] + 1];
The DP array size should be capacity + 1 to cover all weight limits from 0 to capacity.
Complete the code to iterate over all weights from 1 to capacity.
for (int w = 1; w <= [1]; w++)
The outer loop runs from 1 to capacity to fill DP for all weight limits.
Fix the error in the condition to check if current item can fit in the knapsack weight.
if (weights[i] [1] w)
The item weight must be less than or equal to current weight limit to consider it.
Fill both blanks to update the DP array with max value including current item.
dp[w] = Math.Max(dp[w], dp[w [1] weights[i]] [2] values[i]);
We subtract the item's weight from current weight and add its value to find new max.
Fill all three blanks to complete the unbounded knapsack function.
for (int i = 0; i < [1]; i++) { for (int w = 1; w <= [2]; w++) { if (weights[i] [3] w) { dp[w] = Math.Max(dp[w], dp[w - weights[i]] + values[i]); } } }
The outer loop runs over all items, inner loop over weights up to capacity, and condition checks if item fits (weight less or equal).
