Complete the code to initialize the DP array for bottom-up tabulation.
int[] dp = new int[[1]];The DP array size should be n + 1 to include the base case at index 0.
Complete the code to set the base case for the DP array.
dp[0] = [1];
The base case for many DP problems is dp[0] = 0, representing zero items or zero capacity.
Fix the error in the loop condition to iterate over all subproblems.
for (int i = 1; i [1] dp.length; i++) {
The loop should run while i is less than dp.length to avoid index out of bounds.
Fill both blanks to complete the inner loop and condition for the knapsack problem.
for (int w = 1; w [1] W; w++) { if (weights[i - 1] [2] w) {
We loop w from 1 to W inclusive, and check if the current item's weight is less than or equal to w.
Fill all three blanks to complete the DP state update for the knapsack problem.
dp[i][w] = Math.max(dp[i - 1][w], dp[i - 1][w - [1]] + [2]); } else { dp[i][w] = [3];
The DP formula chooses the max between not taking the item and taking it (adding its value and reducing capacity).
