标签:des style blog http color os strong io
Description
Input
Output
Sample Input
Sample Output
1 #include<iostream> 2 #include<cstring> 3 #include<cstdlib> 4 using namespace std; 5 const int maxn= 200050; 6 char st[maxn]; 7 int next[maxn]; 8 int dp[maxn]; 9 int main() 10 { 11 int test,lenb; 12 scanf("%d",&test); 13 while(test--) 14 { 15 scanf("%d %s",&lenb,st); 16 int i=0,j=-1; 17 next[0]=-1; 18 memset(dp,0,sizeof(int)*(lenb+1)); 19 while(i<lenb) 20 { 21 if(j==-1||st[i]==st[j]) 22 next[++i]=++j; 23 else j=next[j]; 24 } 25 //得到了一个next数组... 26 for(i=1;i<=lenb;i++) 27 dp[i]+=dp[next[i]]+1; //求解所有前缀的种类 while(next[i]) 28 int ans=0; 29 for(i=1;i<=lenb;i++) 30 { 31 ans+=dp[i]; 32 ans%=10007; 33 } 34 printf("%d\n",ans); 35 } 36 return 0; 37 }
HDUOJ------3336 Count the string(kmp),布布扣,bubuko.com
HDUOJ------3336 Count the string(kmp)
标签:des style blog http color os strong io
原文地址:http://www.cnblogs.com/gongxijun/p/3880946.html