The railway station usually has some trunk lines that are forked out of the Railway Branch for the train to dock, so as to allow passengers or cargo loading. The Railway Branch has a certain length, and the train has a certain length, and each train has the same length. Suppose there is a small station on a east-west Railway. The station has only one branch road for the railway to dock, and the branch road can accommodate up to M trains. In order to keep the train running smoothly, the station only allows the train to enter the station from the east, and the train from the West, and the first station must exit first. Otherwise, the train in the station will be blocked. The train station is busy with work. Every day, there are n trains heading from the East to the West that require arrival at the scheduled time and a certain period of time in the station. To meet the requirements of each incoming train, the scheduling of small stations is carried out in a well-organized manner. Before starting daily work on the station, the station staff must read the application for all trains and decide which trains are accepted for the competition. For trains that cannot meet the requirements, the station must inform them in advance and ask them to change their route so as not to affect normal railway transportation. By
When a train enters or leaves the station, it is negligible. The station allows several trains to enter or exit at the same time, and the staff of the station can arrange the order of these trains. The principle of small stations is to satisfy the requirements of applying for train as much as possible. Compile a program to help the staff check the arrival application of all trains on a certain day and calculate the maximum number of trains that can meet the requirements. N <= 100, m <= 3;
The question was initially greedy, sorted by the outbound time, and can be entered, but it turns out that this is only applicable to the case where M = 1, when M is greater than 1, it is difficult to determine whether the website can be entered.
The positive solution is divided into three DP. Let's talk about M = 1 and 2, and then M = 3.
First, sort by the inbound time as the first keyword and the outbound time as the second keyword.
When M = 1, F [I] indicates the number of train requests that can be met at the end of the bus I. Initial f [I] = 1; F [I] = max {f [J] + 1} (j <I and j has already logged out before I );
When m = 2, F [I] [J] indicates the last and second outbound route of the I-th vehicle, when J cars are counted down to the first station, the maximum number of train requests can be met. Initial f [I] [J] = 2; f [I] [J] = max {f [k] [I] + 1} (outbound sequence k <I <J, and K has already logged out before J's arrival );