Problem Description
Today is the birthday of SF,so VS gives two strings S1,S2 to SF as a present,which have a big secret.SF is interested in this secret and ask VS how to get it.There are the things that VS tell:
Suffix(S2,i) = S2[i...len].Ni is the times that Suffix(S2,i) occurs in S1 and Li is the length of Suffix(S2,i).Then the secret is the sum of the product of Ni and Li. Now SF wants you to help him find the secret.The answer may be very large, so the answer should mod 1000000007.Input
Input contains multiple cases.
The first line contains an integer T,the number of cases.Then following T cases. Each test case contains two lines.The first line contains a string S1.The second line contains a string S2. 1<=T<=10.1<=|S1|,|S2|<=1e6.S1 and S2 only consist of lowercase ,uppercase letter.Output
For each test case,output a single line containing a integer,the answer of test case.
The answer may be very large, so the answer should mod 1e9+7.Sample Input
2aaaaaaaabababababa
Sample Output
1319
题解
将两个串反转,再进行普通的kmp匹配。
记录模式串的每个前缀(即反转前的后缀)出现的次数,考虑kmp的next数组,f[i]代表1~i包含1~f[i],那么ans[f[i]]+=ans[i];参考代码
#include