标签:ane back similar sub for scanf mes sim output
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 11476 Accepted Submission(s):
5340
#include<cstdio> #include<cstring> using namespace std; int n,m; char s[200010]; int next[200010],dp[200010]; void getnext(){ int k=-1,j=0; next[0]=-1; while(j<m){ if(k==-1||s[j]==s[k]){ j++;k++; next[j]=k; } else k=next[k]; } } int main(){ int T; scanf("%d",&T); while(T--){ memset(dp,0,sizeof(dp)); memset(next,0,sizeof(next)); scanf("%d",&m); scanf("%s",s); getnext(); dp[0]=0; int sum=0; for(int i=1;i<=m;i++){ dp[i]=dp[next[i]]+1; sum=(sum+dp[i])%10007; } printf("%d\n",sum); } }
标签:ane back similar sub for scanf mes sim output
原文地址:http://www.cnblogs.com/cangT-Tlan/p/7606019.html