← Quit0 / 0 correct
AlgorithmsHard1 of 205

What is the recurrence for the classic 0/1 knapsack DP?

dp[i][w] = max(
    dp[i-1][w],
    dp[i-1][w - wt[i]] + val[i]  // if wt[i] <= w
)