Complete the code to initialize the DP array for the unbounded knapsack problem.
dp := make([]int, [1]+1)
The DP array size should be based on the maximum weight capacity W, so we create dp with length W+1.
Complete the code to iterate over all weights from 1 to W.
for w := 1; w <= [1]; w++ {
We iterate weights from 1 to W (maximum capacity) to fill dp array.
Fix the error in the condition to check if current item weight fits in current capacity.
if weights[i] [1]= w {
The item can be included if its weight is less than or equal to current capacity w.
Fill both blanks to update dp[w] with the maximum value including current item.
dp[w] = max(dp[w], dp[w-[1]] + [2])
We subtract the item's weight from current capacity and add its value to dp to update maximum value.
Fill all three blanks to complete the unbounded knapsack function signature and return statement.
func unboundedKnapsack([1] []int, [2] []int, [3] int) int { // function body return dp[W] }
The function takes weights, values slices and capacity W as inputs and returns the max value.
