Dynamic Programming |
Document last modified: |
| int knapsack( capacity ) | |
| 1 | if max ←lookup( capacity ) = NIL then |
| 2 | max ← 0 |
| 3 | for i ← 1 to N |
| 4 | if space ← capacity - size[ i ] ≥ 0 then |
| 5 | if tempmax ← knapsack( space ) + value[ i ] > max then |
| 6 | max ← tempmax |
| 7 | insert( solutions, capacity, max ) |
| 8 | return max |
|
Solutions database
|