Hyperactive Boy Gangsan
Time limit1sMemory limit128 MB
Count minimal subsets of intervals that cover [0, M] with no redundant interval, modulo 10^8, over multiple test cases.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Intervals, Combinatorics, Sorting
- Solved
- No attempts yet
Problem
Gangsan loves being active so much that if he rests for even a single instant during the day, thorns sprout all over his body and he suffers. Having lived like this for 24 years, he has gained the ability to work on any number of tasks at the same time.
A day starts at time and ends at time , and every instant of the day is a real number between and inclusive. Gangsan has a list of tasks he can do today; each task has a start time and an end time . If he picks a task, he is fully active from time to time inclusive (both endpoints included).
Gangsan wants to save his tasks, so he will only pick a minimal subset that satisfies both of the following conditions.
- At every instant of the day he is doing at least one task. In other words, the chosen tasks' intervals cover the whole of .
- Removing any single one of the chosen tasks always creates an instant during the day at which he is doing nothing. In other words, no chosen task is redundant.
Within a minimal subset, several tasks may be running at the same instant.
Given the list of tasks Gangsan can do today, count the number of distinct minimal subsets.
Input
The input consists of several test cases.
The first line of each test case contains the day's end time and the number of available tasks . (, )
Each of the next lines contains a task's start time and end time . ()
The input ends with a line containing two integers , which must not be processed.
Output
For each test case, print the number of minimal subsets modulo , one per line.