Dynamic programming to solve the 0-1 knapsack problem

These days algorithm teacher arranged a job is about the knapsack problem, where the record about the solution process:

A: Describe the knapsack problem

There n1, n2, n3 .... more items, the weight of each item is w1, w2, w3 ....., the value of each item is v1, v2, v3 ...., now we have a bearing C is the weight of the backpack, how to obtain the total value of items put into the backpack of items to make the maximum.
Since only one of each item, and can select or leave, so there is no object with 0 into the backpack, the backpack into the object 1 represents

II: Process Analysis (in particular to analyze the example)

Description Title: conventional bearing may be a knapsack Bag, 3 and 6 of the article, the weight thereof are 2,3,4, 1,2,5 value. Knapsack with dynamic programming to solve this problem, to obtain the best combination
for the convenience of thinking, we gradually increase the weight of the backpack from 0 to 6, and assuming there is a weight of 0 for the item, so we gave four items are numbered 0 , 1,2,3. And you get this form, w represents the weight of items, v represents the value of the goods. The data table shows the current capacity, the maximum value that can be placed, how the data obtained will be analyzed in the back
Dynamic programming to solve the 0-1 knapsack problem
analysis of the problem:
When selecting items into the backpack, there are two possibilities: Suppose the current item number is n

Guess you like

Origin blog.51cto.com/14234228/2444019