标签:des style blog io ar color os sp for
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5097 Accepted Submission(s): 2396
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<set> #include<vector> #include<queue> #include<map> #include<algorithm> #include<cmath> #include<stdlib.h> #include<time.h> using namespace std; #define mmax 200000+10 int next[mmax],ans[mmax],n; char p[mmax]; void get_next(){ memset(next,0,sizeof(next)); for(int i=1;i<n;i++){ int j=i; while(j>0){ j=next[j]; if(p[i]==p[j]){ next[i+1]=j+1; break; } } } } void solve(){ int sum=0; memset(ans,0,sizeof(ans)); for(int i=1;i<=n;i++){ ans[i]=(ans[next[i]]+1)%10007; sum+=ans[i]; } cout<<sum%10007<<endl; } int main(){ int t;cin>>t; while(t--){ scanf("%d",&n); scanf("%s",p); get_next(); solve(); } }
标签:des style blog io ar color os sp for
原文地址:http://www.cnblogs.com/ainixu1314/p/4146939.html