Usaco 2013 Nov silver pogo-cow

Source: Internet
Author: User

Recently, we started to do some usaco silver group questions because of the poor experience (the course is suspended. Abused, Tat

It seems that pogo-cow is the only question that Nov silver can say?

?

Pogo-cow

  • Description

(A straight line has some vertices with weights. You can select a vertex as the starting point, select a forward direction (left or right), and continuously jump forward to another vertex, the score is the weight of this point. The distance between each hop is not smaller than the previous hop, and the maximum score is obtained)

In an ill-conceived attempt to enhance the mobility of his prize cow
Bessie, Farmer John has attached a pogo stick to each of Bessie's legs .?
Bessie can now hop around und quickly throughout the farm, but she has not yet
Learned how to slow down.

To help train Bessie to hop with greater control, Farmer John sets up
Practice Course for her along a straight one-dimenice path using SS his
Farm. at various distinct positions on the path, he places n targets on
Which Bessie shocould try to land (1 <= n <= 1000). Target I is located
Position X (I), and is worth P (I) points if Bessie lands on it. Bessie
Starts at the location of any target of her choosing and is allowed to move
In only one direction, hopping from target to target. Each hop must cover
At least as much distance as the previous hop, and must land on a target.

Bessie earned es credit for every target she touches (including the initial
Target on which she starts). Please compute the maximum number of points
She can obtain.

  • Solution

After thinking for a while, I thought about the algorithm when I went to the evening study class. Then I went back to my bedroom and calmed down for one night. I realized it the next day.

Consider only one direction first. (If it is in another direction, you only need to reverse it)

First, you must sort these points according to the abscissa.

In fact, O (N ^ 3) DP is not difficult to think of: Using F (I, j) indicates the maximum score from I to J and then to the next hop (because only the single direction is taken into account, we assume j> I), then

F (I, j) = W (I) + max {f (j, k)}, k> J and X (k)-X (j)> = x (j)-X (I)

W (I) indicates the weight of vertex I.

Then optimization:

For K in the above equation, if we find the first K that meets the condition, we will find that k + 1, K + 2,..., n all satisfy the condition.

Then we simply maintain the maximum value of a range: use M (I, j) to represent max {f (I, j), F (I, j + 1 ),..., f (I, n )}

The above equation can be rewritten:

F (I, j) = W (I) + M (j, k), k> J and K meet the condition X (k)-X (j)> = The first vertex of X (j)-X (I)

Obviously, we can use binary search to find this K.

As for M (I, j) Maintenance, because K is behind J, we will reverse dp (I and j reverse enumeration), then we will get an F (I, j) then you can update the M (I, j) value:

M (I, j) = max {f (I, j), m (I, j + 1 )}

So far, the complexity of the problem is reduced to O (n2logn ).

?

This method is actually quite common. For example, the following is also the usaco silver question:

Poj 3616 milking time

Description

Bessie is such a hard-working cow. In fact, she is so focused on maximizing her productivity that she decides to schedule her next?N? (1 ≤?N? ≤0. 1,000,000) hours (conveniently labeled 0 ..N-1) so that she produces as much milk as possible.

Farmer John has a list?M? (1 ≤? M? Less than or equal to 1,000) possibly overlapping intervals in which he is available for milking. Each interval?I? Has a starting hour (0 ≤?Starting_houri? ≤?N), An ending hour (Starting_houri? <?Ending_houri? ≤?N), And a corresponding efficiency (1 ≤?Efficiencyi? Less than or equal to 1,000,000) which indicates how many gallons of milk that he can get out of Bessie in that interval. farmer John starts and stops milking at the beginning of the starting hour and ending hour, respectively. when being milked, Bessie must be milked through an entire interval.

Even Bessie has her limitations, though. After being milked during any interval, she must rest?R? (1 ≤?R? ≤?N) Hours before she can start milking again. Given farmer Johns list of intervals, determine the maximum amount of milk that Bessie can produce in?N? Hours.

Input

* Line 1: three space-separated integers :?N,?M, And?R
* Lines 2 ..M+ 1: line?I+ 1 describes FJ's ith milking interval withthree space-separated integers :?Starting_houri?,?Ending_houri?, And?Efficiencyi

Output

* Line 1: the maximum number of gallons of milk that Bessie can product in?N? Hours

Sample Input

12 4 2

1 2 8

10 12 19

3 6 24

7 10 31

Sample output

43

Source

Usaco 2007 November silver

?

The general idea is that there are m time periods that may overlap, and each time period has different benefits, select the time period that satisfies the end time of the previous time period to the start time of the next time period with at least the R interval, and find the maximum benefit.

In fact, this question can be done with a square-level algorithm. However, we can use the above method to optimize it to O (nlogn) based on the poj Server Principle) (sort the intervals by the end time first) use f (I) to indicate the maximum benefit that can be obtained when the last interval is the I, then

F (I) = W (I) + max {f (k)}, k <I and end_time (k) + r <= start_time (I)

Then, use the above method to find the first K that meets the condition and maintain the maximum value of a continuous interval. Note that we should be here this time (because the k we are looking for is in front of I ).

At the request of LZW, write more details:

Let M (I) = max {F (1), F (2),..., F (I-1), F (I)}, then the dynamic equation can be changed:

F (I) = W (I) + M (K), k <I and K are the time periods that meet the end_time (k) + r <= start_time (I) Condition

Similarly, M (I) is maintained after obtaining an f (I:

M (I) = max {f (I), m (I-1 )}

(However, the time is the same as that of LZW's big square algorithm, and LZW, which is so angry with everyone, is paralyzed)

(It is estimated that ZBT will tell me: "Do you need to write an answer to these two questions ?」)

Usaco 2013 Nov silver pogo-cow

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.