Turn to HDU Dynamic Planning (46 questions ~ [Only provides the train of thought and state transition equation]

Source: Internet
Author: User

Rob beries http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2955
A backpack. When you do this for the first time, use the probability as a backpack (enlarge 100000 times to an integer ): in this range, what's the most frustrating is to think of the total probability as the sum of the probability of robbing n Banks... The state transition equation is written as f [J] = max {f [J], F [J-Q [I]. v] + Q [I]. money} (F [J] indicates the ocean that can be snatched under probability J );

The correct equation is: F [J] = max (F [J], F [J-Q [I]. money] * Q [I]. v) f [J] indicates the maximum probability of escaping from the J ocean. The condition is f [J-Q [I]. money] reachable, that is, robbery before;
F [0] = 1, and other initialization values are-1 (0 oceans won't be captured)

Maximum reimbursement http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1864
Another problem with a backpack is that each invoice is either reimbursed or not reimbursed. a 0-1 backpack represents a backpack;
Transition equation: F [J] = max (F [J], F [J-1] + V [I]);
Disgusting: there is such input data as 3 A: 100 A: 200 A: 300

Maximum continuous subsequence http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1231
State equation: sum [I] = max (sum [I-1] + A [I], a [I]); finally sweep one side from start to end
You can also write it as follows:
Max = A [0];
Current = 0;
For (I = 0; I <n; I ++)
{
If (current <0)
Current = A [I];
Else
Current + = A [I];
If (current> MAX)
Max = current;
}

Max sum http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1003
Same as above, maximum continuous subsequence

Largest rectangle http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1506
For each board, Area = height [I] * (J-k + 1) Where j <= x <= K, height [x]> = height [I]; finding J and K is the key. The general method definitely times out. Using Dynamic Planning, if its left height is greater than or equal to itself, the left boundary on its left must satisfy this property, then iterate on the left of the boundary.
For (I = 1; I <= N; I ++)
{
While (A [L [I]-1]> = A [I])
L [I] = L [L [I]-1];

}

For (I = N; I> = 1; I -)
{
While (A [R [I] + 1]> = A [I])
R [I] = R [R [I] + 1];
}

City game http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1505
The enhanced version of 1506 converts two dimensions into the maximum area composed of each row at the bottom. (pay attention to handling continuous and intermittent situations );

Bone Collector http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2602
Simple 0-1 backpack, state equation: F [J] = max (F [J], F [J-V [I] + W [I])

Super jumping http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1087
Maximum increment sub-segment and, state equation: sum [J] = max {sum [I]} + A [J]; where, 0 <= I <= J, A [I] <A [J] <= "" P = "">

Destiny http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2571
State equation: sum [I] [J] = max {sum [I-1] [J], sum [I] [k]} + V [I] [J]; where 1 <= k <= J-1, and K is a factor of J

Monkey and banana http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1069
State equation: F [J] = max {f [I]} + V [J]; where 0 <= I <= J, W [I] <W [J], H [I] <H [J] <= "" P = "">

Big event in HDU http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1171
One-dimensional backpacks take into account the impact of each item one by one. For the first item: If (F [J-V [I] = 0) f [J] = 0;
Where J is a reverse loop and j> = V [I]

Tower http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2084
Bottom-up: DP [I] [J] = max (DP [I + 1] [J], DP [I + 1] [J + 1]) + V [I] [J];

Free pie http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1176
Simple data Tower
Bottom-up computing: DP [I] [J] = max (DP [I + 1] [J-1], DP [I + 1] [J], DP [I + 1] [J + 1]) + V [I] [J]; process Boundary

I need a offline http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1203
A simple 0-1 backpack requires that at least one copy of the offer is received. We can obtain the minimum probability that we cannot get. The state transition equation: F [J] = min (F [J], f [J-V [I] * W [I]); where W [I] indicates the probability of not obtaining (1-F [J]) obtain the maximum probability of an offer for $ J.

Fate http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2159
Two-dimensional full backpack, the second layer and the third layer need to be sequentially cyclic; (0-1 backpack reverse cycle); The status can be understood as, in the backpack attribute is {M (endurance ), S (number of kill monsters)} can obtain the most experience, the previous backpack sacrifices the size, this backpack sacrifices patience and number
Note: During the last scan, the outer circle is patience, and the inner loop is the number of kill monsters. Because the question requires the maximum remaining patience, there is no limit on the number of kill monsters, once the experience is found to be full, it is the optimal solution;
State transition equation: F [J] [k] = max (F [J] [K], f [J-V [I] [k-1] + W [I]); W [I] indicates the experience value of killing the I-th monster, V [I] indicates the endurance consumed.

How to type http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2577
Use two arrays A and B to record the minimum operation steps for printing the I letter when the Caps Lock is enabled or disabled;
The case sensitivity of the letter I must be discussed separately:
Ch [I] Is lowercase: A [I] = min (A [I-1] + 1, B [I-1] + 2); Do not turn on the light directly letter, turn off the light first and then press the letter, and finally keep not turn on the light; B [I] = min (A [I-1] + 2, B [I-1] + 2 ); if you do not turn on the light, press the letter before turning on the light. If you turn on the light, Shift + letter (turn off the light, press the letter before turning on the light to save steps;
Ch [I] is capital: A [I] = min (A [I-1] + 2, B [I-1] + 2 ); B [I] = min (A [I-1] + 2, B [I-1] + 1)

Finally, B [len-1] ++, turn off the light well O (∩) O ~

Coins http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2844
Similar to hdu1171 big event in HDU, one-dimensional DP, reachable

Beans http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2845
Calculate the maximum discontinuous sub-segments and;
State equation: sum [I] = max (sum [J]) + A [I]; where 0 <= j <I-1; <= "" P = "">

Largest submatrix http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2870
Enumerate the maximum full submatrix of A, B, and C, similar to hdu1505 1506

Matrix swapping II http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2830
The maximum complete sub-matrix, bottom of the I behavior, can constitute the Maximum Matrix, because this question can move any column, so as long as it is greater than or equal to the height [I] can be moved together, you can find the number of height> = height [I]. Here, we use Hash + to scroll. First, we can find the number of occurrences of height [I, then, scan hash [I] + = hash [I + 1] in reverse order.

Minimum interception system http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1257
Two Methods: greedy, greedy from the back to the back, and DP;
If (V [I]> max {DP [J]}) (0 <= j <Len)
DP [Len ++] = V [I];

Common subsequence http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1159
Classic DP, Longest Common subsequence
Len [I] [J] = {Len [I-1] [J-1] + 1, (a [I] = B [J]); max (LEN [I-1] [J], Len [I] [J-1])}
Initialization optimization:
For (I = 0; I <A; I ++)
For (j = 0; j <B; j ++)
Len [I] [J] = 0;
For (I = 1; I <= A; I ++)
For (j = 1; j <= B; j ++)
If (else [I-1] = CH2 [J-1])
Len [I] [J] = Len [I-1] [J-1] + 1;
Else
Len [I] [J] = max (LEN [I-1] [J], Len [I] [J-1]);

★Move bedroom http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1421
Status DP [I] [J] is the optimal solution for selecting j pairs for the first I items
When I = J * 2, there is only one option-DP [I-2] [J-1] + (W [I]-W [I-1]) ^ 2
When I> J * 2, DP [I] [J] = min (DP [I-1] [J], DP [I-2] [J-1] + (W [J]-W [J-1]) ^ 2)

★Humble numbers http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1058
If a number is humble number, it is 2 times, 3 times, 5 times, and 7 times is still humble number.
Define f [I] As the I-th humble number
F [N] = min (2 * f [I], 3 * f [J], 5 * f [K], 7 * f [l]), I, J, K and l move each other after being selected
(Through this question, we can understand the ordered array feature)

★Doing homework again http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1789
This is a greedy and classic question;
From the question point of view, each task can be completed or deducted before the deadline. Therefore, you can consider the completion of each person. Since only one task can be completed every day, therefore, the task with a higher score should be prioritized to check whether the task can be completed. If the task can be completed in advance, it does not matter if it occupies the completion date of other tasks, this is because the current task has the largest score, and how long can it take to complete a task, so as to free up more time to complete other tasks;

How always ways http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1978
Two D methods: one is for the current vertex, which points are reachable; the other is for the current vertex to reach those points;
Obviously, the second method is high, because the first method has some unnecessary attempts;
DP [I] [J] + = DP [II] [JJ]; (Map [II] [JJ]> = the distance between two Manhattan points)
It is worth optimizing. The distance between two Manhattan points may be more than once, so the data can be directly read through preprocessing.

Cherish now Thanksgiving life http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2191
Each item can have up to N items and multiple backpacks;
Using the binary idea, each item is converted into several items, and then it becomes a 0-1 backpack.

Piggy-bank http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1114
A full backpack; a general backpack is the maximum value. This is the minimum value;
You only need to modify the initialization, F [0] = 0, and the other values are + ∞;
State transition equation: F [I] [v] = max {f [I-1] [v], f [I-1] [V-K * V [I] + K * W [I]}, where 0 <= K * V [I] <= V

★Max sum plus http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1024
1. For the first n numbers, use V [N] As the base to take M segments:
When N = m, sum [m] [N] = sum M-1] [n-1] + V [N], the nth number is separated into segments;
When N> M, sum [m] [N] = max {sum [M-1] [K], sum [m] [n-1]} + V [N]; where, m-1 [N] is added to sum [m] [n-1], and the number of segments remains unchanged, or the independent segments are connected to the first n-1 number, and the maximum value that can be formed by the m-1 segment
2. space optimization:
Through the state equation, we can see that M segments are only related to M-1 segments, so we use a rolling array to save space.

Fatmouse's speed http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1160
Requirement: The weight increases strictly, the speed decreases strictly, and the original order is not fixed.
Sort by weight or speed, that is, convert the sequence into the longest ascending subsequence after the order is fixed
The DP [I] is the oldest sequence consisting of the bottom I, where DP [I] = max (DP [J]) + 1, where 0 <= JW [J] & S [I] <s [J] using an index array to construct the optimal solution: record the next entry of each entry, and use Max to find the largest DP [0... N], Dex record subscript, backtracking output can be = "" <= "" P = "">

Cstructing roads http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1025
After P or R is arranged in ascending order, the problem is converted to the longest ascending subsequence.
The question data volume is large, and only binary search and N * log (n) algorithms can be used.
Use an array to record the longest sub-sequence of DP [] records. Len indicates the length. If a [I]> DP [Len], it is followed by Len ++; otherwise, find the largest J in DP [] to meet the requirements of DP [J] <A [I], and connect a [I] to the end of DP [J; <= "" P = "">

Fatmouse chees http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1078
DP thinking, with memory-based search; simple question, well handled boundary;

To the max http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1081
Maximum child Matrix
Converts multiple dimensions to one-dimensional Continuous subsequences (hdu1003)

Tortoise and rabbit race http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2059
Not summarized

★Employment Planning http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1158
Status representation: DP [I] [J] is the optimal solution for leaving J individuals for the previous I months; num [I] <= j <= max {num [I]};
J> after max {num [I]} is meaningless, it is a waste of nothing to remember max_n = max {num [I]};
Each item in DP [I-1] may affect DP [I], even if num [I-1] <num [I]
Therefore, DP [I] is obtained using all the items in DP [I-1];
For num [I] <= k <= max_n, recruit when k <J;
When K> J, dismiss and obtain the minimum value.
DP [I] [J] = min {DP [I-1] [K... Max_n] + (recruitment, dismissal, salary );

Dividing http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1059
When one-dimensional DP sum is an even number, it is judged that DP [sum/2] is not reachable.

Human Gene factions http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1080
State transition equation:
F [I] [J] = max (F [I-1] [J-1] + R [A [I] [B [J], f [I] [J-1] + R ['-'] [B [J], f [I-1] [J] + R [A [I] ['-']);

★Doing homework http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1074
This question is compressed in place;
There are 2 ^ n-1 statuses for all tasks.
The state equation is: DP [next] = min {DP [k] + I penalty} Where, next = K + (1 <> The parity of I determines the status K.
The specific implementation is: traverse n tasks in each state. If item I is not completed, the optimal solution of DP [next] is calculated.

Free DIY tour http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1224
The following describes how to deal with the details of a simple digital tower DP;
DP [I] = max {DP [J]} + V [I] where J-> I is the path;
V [n + 1]: Is there initialization? Is there any initialization for the DP array?
This question cannot be solved by taking it for granted as the longest path. It seems that an NP problem cannot be solved.

Relive the World Cup http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1422
The status of this question is not hard to understand. The status indicates that if the remaining money in the previous city is not negative, that is, it is not rushed back to Hangzhou power, then the impact of the remaining money on the next city will be considered; if the remaining portion of the previous city plus the current city is greater than the current city's living expenses, then DP [I] = DP [I-1] + 1;
It is worth noting that the data for this question is 100000. It is impossible to start from each city to get a DP, and the time complexity is n ^ 2. The time has timed out;
This is how I deal with it. After saving the data, connect 1... N data, so the complexity of scanning once is N; and then an optimization, when DP [I] = N, that is, when all cities can be completed, break;

Pearls http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1300
DP [I] = min {DP [J] + V}, 0 <= j <I, V is the value of Category J + 1 jewelry to category I all bought in category I; = "" <= "" P = "">

Zipper http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1501
DP [I] [J] =

★Fast food http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1227
Here, we need a common sense: Take a point from I to J to minimize the sum of the distance from each point in the interval. This point can be proved by graphics (I + J)/2;
DP [I] [J] = max {DP [I-1] [k] + cost [k + 1] [J] Where (I-1) <= k <j status: Create I depots for the first J positions <= "" P = "">

Warcraft http://acm.hdu.edu.cn/showproblem.php? PID = 1, 3008
During the competition, this DP card went to my network center for power failure !!! Slot ~
Because you do not have a blood return effect, you have to wait for a while;
Use DP [I] [J] to indicate the remaining blood volume of the monster in J units of MP in second I. Note that it must be surplus, that is, during initialization, DP [0] [100] = 100; other DP [0] statuses are invalid because your MP is full when there is no war.
In the past, DP solved the problem by using the optimal solution obtained previously. The problem is that the MP automatically restores X units after the attack, and pushes the current state to the next state, if you think about it, you can't try it. The state transition equation is:
DP [I + 1] [J-SK [K]. MP + x] = min (DP [I + 1] [J-SK [K]. MP + x], DP [I] [J] + SK [K]. at; release K skills. Physical attacks can be regarded as at = 1, MP = 0 magic;

Regular word http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1502
F [a] [B] [C] = f [A-1] [B] [C] + F [a] [b-1] [c] + F [a] [B] [C-1];
A> = B> = C;

Advanced fruits http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1503
Enhanced version of the longest common subsequence

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.