Wolves 2
InterviewTime limit2sMemory limit512 MB
Count binary strings of length N in which every given interval contains at most two ones, modulo 1e9+7.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Prefix sum, Combinatorics, Implementation
- Solved
- No attempts yet
Problem
Wolves appear on the road where Yeongseon is standing. The road is divided into zones, numbered through . A single zone holds at most one wolf.
Yeongseon knows pieces of information about the wolves. One piece of information names one interval of zones and means that the interval holds at most two wolves.
Write a program that counts the wolf arrangements satisfying all pieces of information. An arrangement is decided by whether each zone holds a wolf or not.
Input
The first line contains the number of zones and the number of pieces of information . ()
Each of the next lines contains one piece of information as two integers, the leftmost zone number and the rightmost zone number of the interval. () The interval includes both end zones, and the information means that zones through hold at most two wolves in total. The same interval is given more than once in some inputs.
Output
Print the number of possible wolf arrangements modulo 1,000,000,007 on the first line.