Loading topic
dp[i][c] be the best value using the first i items with capacity c. Then dp[i][c] = max(dp[i-1][c], dp[i-1][c-w_i] + v_i) when c >= w_i, and dp[0][c] = 0. Fill rows in increasing i. Keeping one row and iterating capacity downward reduces spac2 min read