Inverse KMP
Time limit1sMemory limit1024 MB
Given a string's KMP prefix-function array and the alphabet size c, count the strings that produce that array, modulo 1e9+7.
- Level
Hard8 of 10
- Topics
- String matching, Combinatorics
- Solved
- No attempts yet
Problem
bobo has just learnt the Knuth-Morris-Pratt (KMP) algorithm. For a string , let , where is the maximum such that . Given and the alphabet size, find the number of strings with , modulo .
Input
The first line contains two integers and , the length of the string and the size of the alphabet (, ). The second line contains integers (). It is guaranteed that at least one solution exists.
Output
Print a single integer: the number of strings that satisfy the condition, modulo .