Inverse KMP
시간 제한1초메모리 제한1024 MB
길이 n인 문자열의 KMP 실패 함수와 알파벳 크기 c가 주어질 때, 그 실패 함수를 정확히 만드는 문자열의 개수를 10^9+7로 나눈 나머지로 구한다.
문제
bobo has just learnt Knuth-Morris-Pratt (KMP) algorithm.
For string , where is the maximum where .
Given and the size of alphabet, find out the number of strings where modulo .
입력
The first line contains integers and , which denotes the length of the string and the size of alphabet, respectively ().
The second line contains integers ().
It is guaranteed that there exists at least one solution.
출력
A single integer denotes the number of strings.