Skip to content

Knapsack from the top down

planning ahead

Level 2 of 3

Also called 0/1 knapsack, memoised and Top-down dynamic programming.

Packs a bag with the most value it can carry, each item taken whole or left behind, by asking for the best for the whole bag and letting that ask smaller questions. Each answer is kept in a memory, so only the cells the answer needs are ever worked out.

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

calls waiting

times asked
0
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.