0-1 knapsack problem, knapsack problem, optimal loading problem, Huffman coding, what are the thoughts of these questions?

Source: Internet
Author: User

0-1 knapsack problem: given n items and a backpack. The weight of item I is WI, its value is VI, the capacity of the backpack is C. How do you choose which items are loaded into your backpack so that the total value of the items loaded into your backpack is greatest?

When selecting items for backpack, there are only 2 options for each item I put in the backpack or not in the backpack. Item I cannot be loaded into the backpack multiple times, nor can I only load part of the item I.

Knapsack problem:

Similar to the 0-1 knapsack problem, the difference is that when you select item I into the backpack, you can select part of the item I, not necessarily all loaded into the backpack, 1≤i≤n.

Workaround: Find the value-to-weight ratio of each item, i.e. value/ weight. Then add the value weight than the largest item, add the end if the weight limit is not reached, and then add the value of the larger weight than the second.

Optimal loading problem:

There is a batch of containers to be loaded with a ship carrying a weight of c. wherein the weight of container i is WI. The optimal loading problem requires determining that as many containers as possible are loaded into the ship without the loading volume being limited.
Solution: Each time the weight of the lightest person.

Huffman Code:

For shorter characters with high frequency, the characters with lower frequency appear with longer encoding. A 0,1 string is specified for each character as its code, and the code that requires either character is not prefixed with any other character code. This encoding is called a prefix code.


The above four problems can be solved by greedy method, from many problems can be solved by greedy method can be seen that they generally have two important properties: greedy choice nature, the best sub-structure properties

Among them, the so-called greedy choice nature refers to the whole optimal solution of the problem can be achieved by a series of local optimal selection, that is, greedy choice. The dynamic programming algorithm usually uses the bottom-up approach to solve the sub-problems, while the greedy algorithm is carried out in a top-down manner.

When the optimal solution of a problem contains the optimal solution of its sub-problem, it is called the optimal substructure property of the problem.



0-1 knapsack problem, knapsack problem, optimal loading problem, Huffman coding, what are the thoughts of these questions?

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.