Binary Strings
Time limit1sMemory limit512 MB
Count binary strings whose length lies in [L, R], is a multiple of K, and contains no two adjacent 1s, modulo 1e9+7.
- Level
Hard8 of 10
- Topics
- Math, Combinatorics, Dynamic programming, Matrix
- Solved
- No attempts yet
Problem
A string made of only 0s and 1s is called a binary string. A boy became interested in binary strings that never place two 1s side by side. At first he counted how many such strings there are for a fixed length.
After solving that, he added more conditions. He now wants the number of binary strings that satisfy all three of the following.
- The length of the string is between and , inclusive ().
- The length of the string is a multiple of an integer ().
- No two 1s appear consecutively in the string.
The count can be very large, so print it modulo 1,000,000,007.
Input
The first line contains the number of test cases ().
Each of the next lines contains three integers , and , separated by spaces.
Output
For each test case, print one line in the form Case x: y. Here is the test case number starting from 1, and is the number of binary strings that satisfy the conditions, modulo 1,000,000,007.
Hint
For , and , only the lengths 3, 6 and 9 are counted. Strings that satisfy the conditions include 101, 000, 010, 101001 and 000010000.