Some greedy classic template

First, the range of issues

1, a plurality of sections, up to the number of the selected section such that the pairwise cross-section.

The right end in ascending order, can choose to choose.

2, number of intervals, each interval the value of the right to elect a number of pairwise cross section, and the maximum weight.

Set \ (F_i \) is the front to back do \ (I \) answers to the right value of \ (W \) interval \ ((L, R & lt) \) , \ (F_r = max (F_r, \ max \ limits_ = {J}. 1. 1-L ^ {} (F_j) + W) \) .

3, a plurality of sections, the selected minimum interval covering the entire sequence.

Ascending order left point, right point of the left edge of the furthest point in the area has been covered, each prefix is ​​the longest period of coverage.

4, a plurality of sections, each section has a cost, a plurality of selected intervals covering the entire sequence, so that the cost is minimum.

Set \ (F_i \) is the front to back do \ (I \) answers for consideration \ (W \) interval \ ((L, R & lt) \) , \ (F_r = min (F_r, \ min \ limits_ = {J}. 1-L ^ R & lt (F_j) + W) \) .

Second, the sequence of questions

1, LIS rise longest sequence

Act One, Fenwick tree

Set \ (F_i \) is the position \ (I \) is the length of the end of the LIS. The \ (F_i = \ max \ limits_ {J \ in [. 1, I) \ Wedge F_j <F_i} () +. 1 \) .
Either directly after discrete Fenwick tree.
In \ (a_i \) is the subscript \ (F \) is the value.
If it is not the longest decline, then just change the two values just fine.
Element may be press \ (a_i \) is the first key in ascending order, \ (I \) is the second key in descending order (in order to prevent the same value update).
Sorted order to do \ (I \) is the subscript \ (F \) is the value.
If it is not the longest decline, then the second key can be sorted in ascending order.

Method two: piggy-half +

Set \ (F_i \) represents the length of \ (I \) values at the end of the LIS minimum number. Obviously \ (f \) monotone did not fall.
For the elements of a sequence \ (a_i \) , we find the last one-half less than \ (a_i \) a \ (F_j \) , then \ (f_ {j + 1} = a_i \) can, each time the answer is found the biggest \ (J + 1 \) .

Guess you like

Origin www.cnblogs.com/cjoierShiina-Mashiro/p/11578406.html