Training camp Day 9 2020.3.9 Dynamic Programming (d)

Day 9 2020.3.9 training

Dynamic Programming (d)

1.HDU-2196

To a tree, there are n nodes, the value of the right side between nodes, the node farthest ask each node which describes how far a defined distance: tree diameter is the most two trees far point right.

answer

Seeking 1: Take any point u, the point farthest away from him to find v, and then find the point farthest from v w, the \ ((v, W) \) diameter.
Seeking 2: Maintenance dp [u] [0/1] is within the subtree of u u endpoint longest path / time long way, the answer is dp [u] [0] + dp [u] [1];

We also have a theorem, for the trees any point on its farthest point must be between two points of a diameter. Therefore, the complexity of the three dfs
can see for themselves after school method for finding proved useful and after 1: https://blog.csdn.net/u011426016/article/details/89164896

2.P1077 placed flowers

Xiao Ming's newly opened flower shop, in order to attract customers, he wanted to put a row of flowers in front of a florist, a total of \ (m \) pots. By investigating customer preferences, Xiao Ming lists the customer favorite \ (n \) flowers, from \ (1 \) to \ (n \) label. In order to display more flowers at the door, the provisions of \ (i \) flowers can not exceed \ (a_i \) basin, the same flowers placed together when placed flowers and flower basis having different types of labels from small to large order of set them.
Calculate, how many different programs, a total placed flowers.

answer

This problem is actually the easiest
f [i] [j] means I took before \ (i \) flowers, took the \ (j \) potted scheme,

f[i][j]+=f[i-1][j-k](0<=k<=ai)

Remember modulo

3.U53204 elective enhanced version

(Original P2014 elective)
https://www.luogu.com.cn/problem/U53204

Now there \ (N \) of courses, each course there are credits for each course or not there is a direct Prerequisite (if the course is a Prerequisite courses b, that is, only finished school curriculum \ (\ text A \ ) , in order to learn the course \ (\ text B \) ). A student from these courses in select \ (\ text M \) courses to learn, and asked him to get the maximum credit is how much?

answer

Tree Backpack O (nm) practices
explanations Valley from Los
https://www.luogu.com.cn/blog/P6174/solu tion-p2014

4. P1091 chorus formation

[Title] surface to be supplemented

answer

Seeking a rise in the longest sequence and a decline in the longest sequence can be.

5.POJ1651

Multiplication game is carried out on a line card. Each card contains a positive integer. In each move, the player took out a card, with its score is multiplied by the number of numbers to its left and right, it is not allowed to take the first one and the last one card. After the last movement, where only two cards. Your goal is to make points and minimum. \ (n \ le 200 \)

answer

dp [i] [j] i ~ j represents a value from the multiplication section to make the most of the game obtained. Obviously the length of time of 3 no choice but to take the middle.
And that the remaining cases can be: take the last enumeration of the number of recursive left and right side, apparently the last ride up is about borders and the final number.

6.HDU5115

To \ (n \) wolves, every attack can kill a wolf, but it will be this wolf \ (\ text A \) attacks and its adjacent two wolves \ (\ text A \) .
Given \ (A, B \) , find the smallest program injured. \ (n \ le 200 \)

answer

dp [i] [j], over the whole big problem i ~ j complete eradication of the wolf how much harm by.
Then obviously we enumerate the last to be eliminated wolves, about recursion, the last wolf attack is Zhizuo left boundary, right boundary of the right hand and its own b a.
In fact, change the nature of the earlier version of the title

7.P1879

A rectangular pasture is divided into a new \ (M \) OK \ (N \) column \ ((. 1 ≤ M ≤ N ≤ 12,1 ≤ 12 is) \) , each cell is a square of land. \ (\ text {John} \ ) intend on a few delicious Gerry planted pasture grass for his cows enjoy Unfortunately, some quite barren land can not be used grass. And, an exclusive piece of grass cows like the feeling, so \ (\ text {John} \ ) will not choose two adjacent land, that is to say, no two have a common edge grass.
Barren land or not to give you a total number of species for planting program he chose? (Of course, the new completely abandoned ranch is also a program)

answer

Nonaggression replica? Limit is still a little big.
Set F [i] [j] represents the state of the i-th row, row i j is the number of programs. Clear

f[i][j]+=f[i-1][k]|j,k合法且互不冲突

So now the key question is how much a land constraints do?
The land situation negated and then with the state &, 0 on the establishment

8.P4170 [CQOI2007] Coloring

Every time you can put a contiguous board painted a given color, after applying the coating color covers the first color. Coloring less exhausted the number reaches the target.

answer

After the interval dp guess is the number of the coloring i ~ j painted certain spent column is not difficult to state f [i] [j].
i == j is

f[i][j]=1

a [i] == a [j] then I just start painting when i and j are completely coated with that

f[i][j]=min(f[i][j-1],f[i+1][j]) 

Otherwise, the background is certainly to be painted separately, that is

f[i][j]=min(f[i][k]+f[k+1][j],f[i][j]);

Homework

1.P1837 Solitaire

2.P1140 similar genes

3.JSK43368

https://nanti.jisuanke.com/t/43368

To (n (n \ le 20) \) \ coordinates, each coordinate has only treasure can dream, you \ ((0,0) \) , at least ask you how far you can collect all types of treasure may dream (you can only go to walk according to the Manhattan distance)

@ 2196 HDU, P1077, U53204, P1091,1651 @ POJ, 5115 @ HDU, P1879, P4170, P1837, P1140

Guess you like

Origin www.cnblogs.com/liuziwen0224/p/xjx9.html