2016 Summer vacation Multi-school Union---Another Meaningproblem Descriptionas is known to all, in many cases, a word has both meanings. Such as "hehe", which not only means "hehe", but also means "excuse me".
Today,?? is chating with Meizi online, Meizi sends a sentence a to??. ?? is so smart and he knows the word B in the sentence have both meanings. He wants to know how many kinds of meanings meizi can express.
Inputthe first line of the input gives the number of test cases T; T test Cases follow.
Each test case contains-strings A and B, a means the sentence Meizi sends to??, B means the word B-which has both MENA Ings. String only contains lowercase letters.
Limits
T <= 30
| a| <= 100000
| b| <= | a|
Outputfor each test case, output one line containing ' case #x: Y ' (without quotes), where x is the ' Test Case number (star Ting from 1) and Y are the number of the different meaning of this sentence. Since This number is quite large, you should output the answer modulo 1000000007.
Sample Input4hehehehehewoquxizaolehehewoquxizaoleheheheheheheowoadiuhzgneninouguriehiehieh
Sample outputcase #1:3Case #2:2Case #3:5Case #4:1
HintIn the first case, "Hehehe" Can has 3 meaings: "*he", "he*", "hehehe". In the third case, "Hehehehe" Can has 5 meaings: "*hehe", "He*he", "hehe*", "* *", "hehehehe". Idea: Recursion (DP) The meaning of the previous statement in the current position is that it contains the current multi-semantics and does not contain the following code:
#include <iostream>#include<algorithm>#include<cstdio>#include<cstring>using namespacestd;Const Long Longmod=1e9+7;Chars[100005];Charss[100005];intnext1[100005];Long Longnum[100005];intpos[100005];voidMAKENEXT1 (Const Charp[]) { intq,k; intm =strlen (P); next1[0]=0; for(q =1, k =0; Q < m; ++q) { while(k >0&& P[q]! =P[k]) k= next1[k-1]; if(P[q] = =P[k]) {k++; } Next1[q]=K; }}Long LongCalcCharT[],Charp[]) { intn,m; inti,q; inttot=0; N=strlen (T); M=strlen (P); Makenext1 (P); for(i=0, q =0; I < n; ++i) { while(q>0&&p[q]!=t[i]) Q=next1[q-1]; if(p[q]==U[i]) {Q++; } if(q==m) {Long Longflag=1; Pos[tot]=i-m+1; if(tot>0) { if(pos[tot-1]+m<=Pos[tot]) {Num[tot]=(2*num[tot-1])%MoD; } Else{Num[tot]=num[tot-1]%MoD; for(inth=tot-2; h>=0; h--) { if(pos[h]+m<=Pos[tot]) {Num[tot]= (Num[tot]+num[h])%MoD; Flag=0;///When there is no previous statement that does not overlap; Break; }} Num[tot]= (Num[tot]+flag)%MoD; } } Else{Num[tot]=2; } tot++; } } if(tot==0)return 1; returnnum[tot-1];}intMain () {intT; intCase=1; CIN>>u; while(t--) {scanf ("%s%s", S,SS); printf ("Case #%d:%lld\n", case++, Calc (s,ss)); //cout<< (Calc (s,ss)%mod+mod)%mod<<endl; } return 0;}
2016 Summer vacation multi-school joint---another meaning