Backpack
Understand the Nine Lectures on Backpacks
01 Backpack , that is, items are limited.
for 物品
for 容量(倒序)
- P1048 [NOIP2005 Popularization Group] Collecting Herbs [ Original Question | Solution]
- P1049 [NOIP2001 Popularization Group] Packing Problem [ Original Question | Solution]
- P1507 NASA's Food Plan [ Original Question | Solution]
- P1510 Jingwei Reclamation [ Original Question | Solution]
Complete backpack , i.e. unlimited items.
for 物品
for 容量(正序)
Note that climbing stairs (LeetCode 70) requires an orderly sequence , but a general complete backpack does not need to be ordered, such as the classic coin collection: interview question 08.11. Coins . Note the difference between the two cases! The former recycles capacity first and recycles items, while the latter recycles items first and then recycles capacity.
-
P1832 A+B Problem (re-upgrade) [ Original question | Solution]
-
Change Exchange ( LeetCode 322 )
-
Change Change II (LeetCode 518)
-
Combined Sums IV (leetcode 377)
-
Perfect Square Numbers (LeetCode 279)
-
Word Splitting (leetcode 139)
Group backpacks . The items are divided into several groups, and the items in each group conflict with each other, and at most one is selected.
for 组号
for 容量
for 组内物品
- P1757 Babel's Group Backpack [ Original Question | Solution]
Multiple knapsacks , there are at most n[i] items available for the i-th item. It is a special case of grouping backpacks. It can be understood as follows: for the i-th item, only one of 0, 1, 2, 3, 4...n[i] can be selected.
for 物品种类
for 容量
for 该类物品数量
Requires binary optimization to 01 knapsack if timeout
- P2066 Machine Allocation [ Original Question | Solution]
- P1776 Treasure Screening [ Original Question | Solution]
mixed backpack
Some items are infinite (complete), and some items are finite (multiple). Process the complete knapsack first, and then convert multiple knapsacks into 01 knapsacks through binary optimization.
- P1833 Cherry Blossoms [ Original Title | Solution]
A backpack that satisfies a certain condition
- P1509 Search and search and search for GF [ Original question | Solution]
2D true false backpack
- P1877 [HAOI2012] Volume adjustment [ Original question | Solution]
Invest in stocks, multiple dp
- P1853 Maximum Benefit of Investment [ Original Question | Solution]
dynamic programming
First record the most recently encountered state dp.
- Robbery ( LeetCode 198 ) [ Original Problem Solution ]
- House robbery (upgrade topic, after selecting i, i-2, i-1, i+1, i+2 can not be selected, ask the maximum value that can be stolen) [original question solution]
- House robbery (upgrade question, you can steal 2 consecutive households, but you can't steal 3 consecutive households, ask the maximum value that can be stolen) [Original Problem Solution]
- House robbery (upgrade question, you can't steal consecutive residents, but there are k opportunities to steal consecutive residents, ask the maximum value that can be stolen) [Original Problem Solution]
- Robbery III ( LeetCode 337 ) [Original Problem Solution]
- Best Time to Buy and Sell Stocks III (LeetCode 123)
- Best Time to Buy and Sell Stocks IV (LeetCode 188)
- The best time to buy and sell stocks includes a freezing period (LeetCode 309) [ Original Problem Solution ]