0/1 knapsack

In a game you can carry at most 5 kg. Three treasures lie in front of you. Which whole treasures earn the most points?

Each treasure has a weight and a value. Consider it once and decide whether to take it.

Visit capacities from largest to smallest. The remaining space still holds a result from earlier items, so the current treasure is counted at most once.

For n items and capacity C, time is O(n × (C + 1)) and space is O(C + 1).