# hdu6153（kmp） A Secret

2017年08月19日 10点热度 0人点赞 0条评论

# A Secret

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 256000/256000 K (Java/Others)
Total Submission(s): 195    Accepted Submission(s): 83

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

2
aaaaa
aa
abababab
aba

Sample Output

13
19

Hint

case 2:
Suffix(S2,1) = "aba",
Suffix(S2,2) = "ba",
Suffix(S2,3) = "a".
N1 = 3,
N2 = 3,
N3 = 4.
L1 = 3,
L2 = 2,
L3 = 1.

ans = （3*3+3*2+4*1）%1000000007.

#include
#include
#include
using namespace std;
#define ll long long
const int mn=1e6+5;
int n,m,nextval[mn];
char s[mn],t[mn];
ll id[mn];
const int mod=1e9+7;
void getNextval() {
int i=0,j=-1;
nextval[0]=-1;
while(i0;--i)
{
id[nextval[i]]+=id[i];
ans=(ans+id[i]*i)%mod;
}
printf("%lldn",ans);
}
return 0;
}


update