Magic Strings
Time limit4sMemory limit512 MB
Given n up to 10^18, count the distinct subsequences of the recursively doubled string F_n modulo 10^9+7 for up to 10 test cases.
- Level
Hard9 of 10
- Topics
- Dynamic programming, Matrix, String, Combinatorics
- Solved
- No attempts yet
Problem
Consider the sequence of strings defined as follows.
ab
b
Calculate the number of distinct subsequences of the string modulo .
Input
The first line contains a single integer (), the number of test cases. The second line contains integers (), one for each test case.
Output
For each test case, output the single integer that is the answer to the problem. Separate consecutive answers with single spaces.
Hint
The first three strings are: = ab, = ababb, and = ababbababbb.