Skiing (DP)

Source: Internet
Author: User

Description: Bessie went skiing in Colorado, but she didn't know much about it yet. It was just a scum with a capacity of 1. Bessie enters the ski resort from, and must leave as soon as it reaches T. There are n slopes in the ski resort, and it takes di minutes to slide the first slope, requiring visitors to enter when their capabilities reach CI or above. Bessie is determined to take some skiing courses to improve his own quality, so that he can slide several times in a limited time.

The ski resort offers s courses. The start time of the Class I is Mi, which lasts for Li minutes. If you want to take the course, you cannot be late or leave early. After the course, Bessie's skiing capability will become AI. Note that it is not the ability to increase the AI, but the AI, so disorderly class will actually lead to a decline in the ability. Bessie can arrange her time at will: skiing, attending classes, or taking a cup of cocoa delicious. How does she arrange the course and skiing time to maximize the number of landslides? (Too lazy to summarize ..)

The same slope can be slide countless times.

 

Input Format

 

• First line: Three integers t, S and N, 1 ≤ T ≤ 10 ^ 4, 1 ≤ S ≤ 100, 1 ≤ n ≤ 10 ^ 5

 

• Line 2 to S + 1: line I + 1 describes the I courses, including Mi, Li, and AI, 1 ≤ Mi, and Li ≤ 10 ^ 4.

 

, 1 ≤ AI ≤ 100

 

• Lines S + 2 to S + n + 1: lines S + I + 1 Describe the I slope, which are Ci and Di, 1 ≤ CI ≤ 100, respectively, 1 ≤ di ≤ 10 ^ 4

 

Output Format

 

• A single integer indicates the maximum number of times that Bessie can slide.

 

Problem solving process:

1. At the beginning, the data was so scared .. I couldn't find a clue at all, and then I began to look at the data range and try again. The status must be at least two-dimensional, and the current capability value must be included in the status (because the maximum is only 100 ), then n will certainly not be used as the status (otherwise 10 ^ 5*100 = 10 ^ 7, the transfer must be O (1) To not time out, and O (1) the transfer is definitely not possible .). The time t can only be used as the status .. F [I] [J] indicates the maximum number of slides when the time is I and the capability value is J .. Then I read the following example to explain that the same slope can be slide countless times. I didn't even mention it in the question, but I had no idea how to look at the example below ..

In the future, you must carefully read the sample explanations and fully understand the meaning of the question ..

2. Since the same slope can be slide many times, we will definitely choose the slide that can be slide at present and will spend the least time slide. Therefore, t [I] is used to process the minimum cost of a hillside with the required capacity value of I. Scan it to find the minimum cost of the slope that can be slide when the current capacity value is I. Can [I] = min (can [I-1], t [I]);

3. for state f [I] [J], you can first inherit the value of F [I-1] [J, then it can be transferred by F [I-Can [J] [J] + 1 (slide the hill with the minimum cost ).

What if I learned a course? Obviously, if you want to take a course and the course end time must be less than or equal to I, you only need to consider that the course end time is equal to I, because f [I] [J] inherits the value of F [k] [J] (k <I ). Then, the course [I] [J] is processed in advance, indicating that the end time is I, and the minimum time required for the course with the capacity value J after learning. If the course does not exist, it is infinite. There are:

F [I] [J] = max (F [I-1] [J], F [I-Can [J] [J] + 1, max (F [I-course [I] [J] [k]), k <j.

 

Max (F [I-course [I] [J] [k]) can be saved using S [I] [J], then the equation becomes

F [I] [J] = max (F [I-1] [J], F [I-Can [J] [J] + 1, s [I-course [I] [J] [J-1]);When F [I] [J] is obtained, s [I-course [I] [J] [J-1] has been obtained.

Skiing (DP)

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.