Dynamic Programming Method -- solving the 0-1 knapsack problem

Source: Internet
Author: User



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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.