K-Uniform String
Time limit1sMemory limit256 MB
Count binary strings of length N where, for each of M given intervals, every length-K substring inside it contains the same number of ones, modulo 1e9+7.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Combinatorics, Math, Prefix sum
- Solved
- No attempts yet
Problem
Take a string made of 0s and 1s. If every contiguous substring of length holds the same number of 1s, call the string -uniform.
For example, the string 100110 is 4-uniform. Its contiguous substrings of length 4 are 1001, 0011 and 0110, and each one holds two 1s.
Onjo wants to build a string of 0s and 1s with length . Onjo has favorite intervals and favorite numbers. The -th interval means the substring from the -th character to the -th character, and the -th number is . Onjo wants the substring of the -th interval to be -uniform. is not larger than the length of the -th interval.
Count the strings Onjo can build. The count can get large, so print it modulo 1,000,000,007.
Input
The first line contains and . (, )
The -th of the next lines contains , and . (, )
Output
Print the number of strings Onjo can build, modulo 1,000,000,007.
Hint
In the first example the eight strings are 00000, 00001, 01010, 01011, 10100, 10101, 11110 and 11111.
The second example gives Onjo no favorite interval and no favorite number, so any string of length works. That leaves strings.