MHLAR10 - Hyperactive Girl

no tags 

 

 

English Vietnamese

 

 

 

Gene and Gina have a particular kind of farm. Instead of growing animals and vegetables, as
it is usually the case in regular farms, they grow strings. A string is a sequence of characters.
Strings have the particularity that, as they grow, they add characters to the left and/or to the
right of themselves, but they never lose characters, nor insert new characters in the middle.
Gene and Gina have a collection of photos of some strings at different times during their growth.
The problem is that the collection is not annotated, so they forgot to which string each photo
belongs to. They want to put together a wall to illustrate strings growing procedures, but they
need your help to find an appropriate sequence of photos.
Each photo illustrates a string. The sequence of photos must be such that if si comes imme-
diately before si+1 in the sequence, then si+1 is a string that may have grown from si (i.e., si
appears as a consecutive substring of si+1). Also, they do not want to use repeated pictures,
so all strings in the sequence must be different.
Given a set of strings representing all available photos, your job is to calculate the size of the
largest sequence they can produce following the guidelines above.

 

Helen is a hyperactive girl. She wants to schedule her activities so that at any moment of the day there is at least one thing she can do. She does not care if her activities overlap in time, as long as every moment of her day has an activity scheduled.
Helen divided the day in a particular way. The day starts at time 0 and finishes at time M. Each moment of the day is represented by a real number between 0 and M, inclusive. Helen made a list of all possible activities, with their start and finish times. Now she must decide which subset of activities to schedule.
If an activity starts at time S and finishes at time F, then we say that it covers all moments between S and F, inclusive. Helen does not want to waste any activities, so she will only choose minimal subsets of activities that cover the day to be scheduled. A subset of activities is a minimal subset that covers the day if and only if:
1. every moment of the day is covered by at least one activity of the subset; and
2. removing any of the activities from the subset would leave at least one moment of the day uncovered.
Note that some moments of the day may be covered by more than one activity.
Given the list of possible activities for one day, you must help Helen by determining how many distinct minimal subsets cover the day.

 

Input


 

Each test case is given using several lines. The first line contains two integers M and N, representing respectively the highest value for a moment in the day (1 ≤ M ≤ 10^9) and the number of possible activities for the day (1 ≤ N ≤ 100). Each of the next N lines describes one possible activity and contains two integers S and F, representing respectively the start and finish times of the activity (0 ≤ S < F ≤ M).

The last test case is followed by a line containing two zeros.

 

 

Output

 

For each test case output a single line with a single integer representing the number of minimal subsets that cover the day. To make your life easier, print the remainder of dividing the solution by 10^8.

 

 

Sample

input
8 7 0 3 2 5 5 8 1 3 3 6 4 6 0 2 1 1 0 1 2 1 0 1 0 0

output
4 1 0

 

 


hide comments
waddlepoof: 2015-09-23 16:47:35

read carefully

Hussain Kara Fallah: 2013-09-07 14:22:41

Done In O(N^2)

[Hakuna Matata]: 2012-09-23 01:12:02

the problem is not this, read again!
also [0, 2]+[1, 3]+[3, 6]+[5, 8] is solution in first case because--> A subset of activities is a minimal subset that covers the day if and only if:
1. every moment of the day is covered by at least one activity of the subset; and
2. removing any of the activities from the subset would leave at least one moment of the day uncovered.

Haidar Abboud: 2012-07-30 23:12:57

Can anyone explain why the answer for the first testcase is 4 ?

solving by hand yields answers
[0 , 3] + [3 , 6] + [5 , 8]
[0 , 3] + [2 , 5] + [5 , 8]
[0 , 2] + [2 , 5] + [5 , 8]

we can't cover the entire day with less than 3 intervals , and only 3 distinct subsets exist

Ashish Khurange: 2012-06-21 13:45:35

Pay attention to --->

"To make your life easier, print the remainder of dividing the solution by 10^8."

David Gómez: 2010-11-19 15:41:31

Got AC using an O(N^3) algorithm. Can it be solved in O(N^2)?


Added by:~!(*(@*!@^&
Date:2010-11-05
Time limit:0.157s-0.919s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:ACM ICPC2010 – Latin American Regional