求num[i] ,表示1~i前缀 的合法子串个数( 满足前后缀相等,且不重合
#include <iostream> #include <cstring> using namespace std; const int N =1e6+3 ,mod= 1e9+7; #define int long long char a[N]; int n,p[N]; void init(){ int i,j=0; p[1]=0; for(i=2;i<=n;i++){ while(j>0&&a[i]!=a[j+1]) j=p[j]; if(a[i]==a[j+1]) j++; p[i]=j; } } signed main(){ int i,j,tes; cin>>tes; while(tes--){ cin>>a+1; n=strlen(a+1); init(); int ans=1; for(i=1;i<=n;i++){ int t=0; for(j=i;j>0;){ if(p[j]*2<=i) t++; j=p[j]; } //printf("%d: %d\n",i,t); ans*=t; ans%=mod; } cout<<ans<<endl; } }
标签:include,P2375,long,NOI2014,int,init,tes,动物园 From: https://www.cnblogs.com/towboa/p/17192552.html