Skip to main content

Practice · 3 of 6

Clinic: The Doubled Item

CHALLENGE
Difficulty: advanced+25 XP

**Bài toán.** 0/1 knapsack: n items, capacity W; maximize total value. n ≤ 500, W ≤ 100000, values ≤ 10^9. **The submission below loops capacity FORWARD — Wrong Answer.** Which test exposes it? Fix the loop (and be ready to say WHY forward breaks 0/1). ``cpp for (int i = 0; i < n; ++i) for (long long c = w[i]; c <= W; ++c) dp[c] = max(dp[c], dp[c - w[i]] + val[i]); ``

Back to lesson: Practice: Clinic Set 1 — Six Classic Bugs