Items

WeightValue

Capacity

Playback

Stats

Items—
Capacity—
Current cell—
Optimal value—
Chosen items—
Total weight—
Greedy value—
Fill dp[i][w] = max(dp[i-1][w], dp[i-1][w-wᵢ] + vᵢ) — skip the item or take it. After the table is full, backtrack from dp[n][W] to recover the exact subset that reaches the optimum, then pack it.