Give a string and calculate the number of times all prefixes appear in the string.
Solution: After KMP calculates the Next array, the Next array at each position is continuously recursive forward, and 1 is added for each prefix.
Code:
/******************************************************* author:xiefubao*******************************************************/#pragma comment(linker, "/STACK:102400000,102400000")#include
#include
#include
#include
#include
#include
#include #include
#include
#include
#include
#include
//freopen ("in.txt" , "r" , stdin);using namespace std;#define eps 1e-8const double pi=acos(-1.0);typedef long long LL;const int Max=200100;const int INF=10007;int Next[Max];int num[Max];char s[Max];int len=0;void get_next(){ int i=0; int j=Next[0]=-1; while(i
>t; while(t--) { //memset(num,0,sizeof num); scanf("%d",&len); scanf("%s",s); get_next(); for(int i=0;i<=len;i++) { num[i]=1; int t=Next[i]; while(t>0) { num[t-1]=(num[t-1]+1)%INF; t=Next[t]; } } int ans=0; for(int i=0;i