Decomposition
Time limit3sMemory limit512 MB
For each string, sum the products of smallest periods over all ways to split it into substrings, modulo 1e9+7.
- Level
Hard8 of 10
- Topics
- String matching, Dynamic programming
- Solved
- No attempts yet
Problem
You are given a string . You want to partition it into several (possibly one) nonempty substrings. There are ways of partitions. For example, aba, ab+a, a+ba, a+b+a are all the partitions of the string aba.
The weight of a substring is the length of the shortest string such that . For example, the weight of aaa is , and the weight of ab is . The weight of a partition is the product of the weights of all substrings in it.
Output the sum of the weights of all partitions, modulo .
Input
The first line contains an integer (), the number of test cases.
Each test case is on its own line and contains a string () made of lowercase English letters. The sum of over all test cases is at most .
Output
For each test case, output the answer modulo on its own line.