Problem description
The biggest difference between a 0-1 backpack problem and a backpack problem (greedy method-a backpack problem) is that the sub-Problems of the backpack problem are not related to each other, so you only need to find a solution and then use the greedy algorithm, it is okay to obtain the local optimal solution, but the problem of the 0-1 backpack is more complicated because the item cannot be further divided, resulting in a connection between the sub-problems.
Problem Analysis
1. describe the structure of the optimal solution of the Knapsack Problem
2. Mathematical Description
Interpretation of pseudocode
After the segment code operation is complete, for the C [I, w] table:
Then, based on the table constructed above, find the optimal solution:
Summary
When determining whether the I-th item is contained, the dynamic programming method determines whether the C [I, w] is equal to C [I-1, w] to determine whether the I-th item is contained, it seems clever, but the process of constructing the C [I, w] Table above feels that the workload is great.
Dynamic Programming Method -- solving the 0-1 knapsack problem