Skip to content

0/1 knapsack

planning ahead

Level 2 of 3

Also called Zero-one knapsack problem and Knapsack, by dynamic programming.

Packs a bag that holds only so much weight with the most value it can carry, each item taken whole or left behind. Taking the most valuable first is not always best, so a table holds the best for every start of the items and every room up to the bag's.

the most value: the items down the side, the room along the top

cells filled
0

step 1 of 1

Examples

Up to 4 items, each a weight from 1 to 8 and a value from 1 to 99 with a space between, separated by commas, then a semicolon and what the bag holds, from 1 to 8, for example 4 50, 2 30, 3 40; 5.