[DP _ backpack album] [10.14 latest update]

Source: Internet
Author: User

This short time I read the paper "Nine lectures on backpacks", saw the beauty of the solution to the problem of backpacks, also saw the application of the problem in reality, summed up a sentence: the problem is worth looking.

A knapsack problem can be summarized into a model like this: There are several options, each of which has a certain price and value, and some options will get a specific status, how can we get a specific status under the agreed conditions? The status here can be a combination of price and value or other two. This type of problem requires enumeration of each State, but the number of enumeration times can be reduced through dynamic planning to improve efficiency. The main idea is to use the previous state for each transition to obtain the current state. This type of problem is rarely greedy. First, it is difficult to prove whether the policy is correct. Second, greed must reduce the number of enumerations, leading to incorrect results.

I personally think that many of the models mentioned in section 9 are essentially two models: the 01 model and the full model. You can understand the two models thoroughly and then look at other models. This will definitely get twice the result with half the effort.

A special topic was introduced during the course of reading the 9-pack lecture. There were about 26 topics, mainly HDU and poj, which were difficult and easy to answer. This album mainly explained these questions, there are also some simple questions about the UVA backpack that will be added to this album. This album only lists the basic ideas. If you want to read the detailed ideas or code, go to my blog and find out. I have written problem-solving reports for most of the questions.

I. 01 backpack problems (enumeration of items first, and then enumeration of capacity in reverse order) 1. HDU 2602 bone collector is a very common 01 backpack problem, which can be done using one-dimensional and two-dimensional arrays, one dimension is much faster.
2. poj 3624 charm bracelet bare 01 backpack Problem
3. Choose a number of options for the HDU 2546 meal card to minimize the remaining money. The size of the backpack is the money at the beginning, the size of the item is the price of the food, and the answer is recorded when the status is transferred.
4. The average 624 backpack of the ultraviolet a cd, but the output path is required. When the status is transferred, the system records whether the current item is selected in the current status, and then recursively solves the problem.
5. For the Balance Problem of the UVA 562 dividing coins, accumulate the total value of n coins to get sum, and then use sum/2 as the backpack capacity to perform the 01 backpack processing for n coins, it depends on the maximum capacity that can be composed.
6. The optimal problem of HDU 2955 robberies (recommended) robbery solution requires a simple conversion. What we want is the probability of not being captured, not the probability of being captured, the total savings of each bank is the size of the backpack, and the size is a single silver
Row savings, value is the probability of not being caught.
7. poj 2184 cow Exhibition (recommended) deformation of the 01 backpack, in fact, the essence of the problem is to ensure IQ and sense of humor and not negative number of the largest and. Size of IQ attributes, value of sense of humor, and problem Conversion
The sum of the volume and value when the volume is greater than or equal to 0.
8. HDU 2639 Bone Collector II solves the 01 knapsack problem of the k-th largest value. The technique is to add one dimension to indicate the value of the k-th largest, during the transfer, the second dimension is constantly updated by merging two ordered series.
9. poj 2923 relocation (recommended, more comprehensive) uses the State compression idea 01 backpack. The status when multiple items are selected. The total status is 1 <n to determine whether the items in the set can be transported at a time. If yes
Consider this status as an item. After preprocessing, find the tot items and perform a 01 backpack processing on the tot items. The size of each item is State [I] and the value is 1, find the minimum value of the required n items. State transition equation: DP [j | K] = min (DP [j | K], DP [k] + 1) (K is State [I, 1 <= j <= (1 <n)-1]) 10. HDU 3466 proud Merchants: Sorting by Q-P before processing, hard to think, easy to think. 11. HDU 2126 buy the souvenirs has n items, which cost RMB M. Each item can be bought once at most. You can buy several items at most and output the number of solutions. Add one dimension to indicate that you have bought several items. 12. The HDU 4281 judges 'response (recommendation and comprehensive questions) is similar to the above 9th ideas. However, the judgment conditions for this question are simpler. The question is MTSP, a classic one. For more information, see here 2. Full Knapsack Problem (enumeration of items first, then enumeration of capacity in the forward order) 1. The total number of solutions for the WordPress 674 coin change solution is only five coins. 2. The enhanced version of the question on the WordPress 147 dollars has 11 types of coins. In addition, the question is input using double, so the accuracy should be considered. 3. The poj 3181 dollar dayz must use a fully-precision simulation backpack. 4. The question of poj 1787 Charlie's change was originally a problem of multiple backpacks, but the speed of solving the problem was extremely fast. 5. poj 3260 the fewest coins (recommended, more comprehensive) full backpack and multiple backpack mixed questions, first use a full backpack to pre-process the coal boss to find the minimum number of coins, the minimum number of coins used by multiple backpacks. 6. poj 2063 investment seeks to obtain the largest investment in K years, and selects the largest interest option every year to obtain the most RMB after K years of investment. 7. 3623 create a tower with battle ships to create a monster. There are N types of towers. You can create any number of them and create a tower with time. A created tower can keep hitting monsters. Take time as the capacity, and take the amount of blood that hits each other as the value. 8. zoj 3524 crazy shopping (recommended) topological sorting + full backpack, first sort them in a simple order. Note that there may be several starting points, and then shift them in a topological order, perform a full backpack for the next vertex each time you transfer the package, and pay attention to the new energy. 9. zoj 3662 math magic's just-concluded question H of the Changchun semi-finals, using each M factor as an item, we are required to select K items at will so that the total number of these items is N, the LCM is M. DP [I] [J] [k] indicates the number of I items selected and the number of solutions where the JLCM is K. The specific method is to pre-process all the factors of M, in this case, no matter how you choose it, the LCM may be m at last, saving a lot of unnecessary calculations and then using this type of backpack for transfer.
Iii. Multiple backpacks (enumeration of items first, and then enumeration of capacity in the forward order) 1. HDU 1114 piggy-bank simple multiple backpacks, but as a 01 backpack, no problem at all, 2. HDU 1059 dividing is a simple multi-pack with a size of coin and a value of currency. It can be processed in binary format into a 01-pack for solving the problem. It can be optimized with 30-bit num. 3. HDU 2191 mourns the victims of the 512 Wenchuan earthquake-Cherish the present and appreciate the super-long and simple multi-backpack title of life, which can be solved with a 01 backpack. 4. poj 1276 cash machine multiple backpacks, which must be processed in binary format as 01. The volume is the number of coins and the value is the currency. 5. the maximum capacity of poj 2392 space elevator is variable. The size is the height of each block. Due to the feasibility, there is no value in this concept.
Iv. Grouping and knapsack problems (first enumeration of capacity in reverse order and then enumeration of items) 1. HDU 1712 acboy needs your help course selection and review problems. You can only select one course if you have no courses, to maximize the benefits. Each course corresponds to a group and each time corresponds to an item. 2. HDU 3033 I love sneakers! XX shopping questions, the deformation of the group backpack, each brand at least one pair, which is different from the Group at most, but the idea is the same, items for each brand of all kinds of shoes. 3. For poj 1837 balance balancing, calculate the weights of each weight in each position, group each weight, and set items in several locations, the final result is the number of solutions with 0 values. 4. poj 3211 shopping clothes show happiness questions. The cost of clothes of each color is the time for washing clothes. The minimum time for solving each group is accumulated one by one.
5. HDU 3810 magina (recommended, comprehensive) Search and grouping backpack. The grouping backpack must be simulated using a monotonous queue. Because of its large capacity, it cannot be transferred as usual. 6. HDU 3535 areyou busy (recommended, hybrid backpack), a variety of hybrid backpacks, requiring a deep understanding of 01, full, and multiple backpacks. 5. tree-shaped backpack (grouping and processing on trees)

1. poj 1155 tele regards each node's sub-nodes as a group of backpacks. The maximum capacity is the number of leaf child nodes. The selected capacity is the selected capacity, value is the money-transfer fee you give. The solution report here 2, HDU 1011 Starship Troopers is similar to the above question. To select a parent node, you must first select a sub-node and specify M as 0. 3. poj 1947 rebuilding roads calculates to delete at least a few sides so that the number of subtree nodes is P. The specific model is similar to the previous question. Solution Report: 4. HDU 1561 the more. The better selects several vertices on a tree to obtain the maximum value. to select a child node, you must first select the parent node, the solution is the same as the above two questions. Solution report here
5. HDU 4003 find metal mineral (recommended, good question) The Grouped backpack with the tree-like DP + selected and only one item can be selected. It is hard to find the state transition equation. The solution report is here 6. poj 2486 apple tree DP + grouping backpack, but the state transition equation should be divided into three steps, which is difficult to think about. Solution Report: Here 7, poj 3345 bribing FIPA tree DP + grouping backpack, there is no special difference compared with the previous questions, just pay attention to the input. VisibleHere
8. HDU 4044 geodefense tree-like DP + grouping backpack requires that the smallest HP be obtained from each son node, and then find the largest combination of these sons. For the solution report, see here

9. zoj 3627 treasure hunt II tree-shaped DP + grouping backpack, water questions for the Zhejiang University monthly competition, very common tree-shaped backpack. This article will be updated constantly. If you haven't met these five types of backpacks in the future, I will sort them into this topic and hope you will keep your attention. This article is original in zeroclock, but it can be reproduced, because we are brothers.

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.