Sunwoo's Setlist
InterviewTime limit1sMemory limit512 MB
Count the ordered song sequences, with repeats allowed, whose running times sum to exactly N minutes, modulo 1,000,000,007.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Math
- Solved
- No attempts yet
Problem
Sunwoo wants to dazzle the students of Ajou University with a rousing live performance at the university's first festival in three years. Sunwoo plans a performance of exactly () minutes, but has not yet decided which songs to play, in what order, or how many times each one should be played.
For example, suppose there are these candidate songs: 1. , Peace like an Ajou River, 3 minutes; 2. , Compsci Boy, 2 minutes; 3. , Brown Earrings, 1 minute; 4. , Not Easy, 5 minutes; 5. , Yoda, 4 minutes.
If Sunwoo builds a 10-minute show from these songs, a valid performance is [3, 1, 3, 4], meaning songs 3, 1, 3, and 4 in that order. As this shows, Sunwoo never takes a break in the middle! The same song may be played several times, and some candidates may not be used at all. The ordered list of songs played in a performance is called a setlist.
Given the number of candidate songs and the running time of each one, help Sunwoo count the setlists that make a performance of exactly minutes.
Input
The first line contains () and (), separated by a space, where is the number of candidate songs. Each of the next lines contains the running time (, ) of song .
Output
Print the number of possible setlists modulo (). If no setlist can be formed, the answer is .