字符窜匹配问题..用kmp写了一遍超时了...最后只好自己DP,应该也不知道算不算DP,连数组都省了...
#include<stdio.h>
char str[200000];
int main()
{
int t,n,i,j,num[200000];
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
scanf("%s",str);
j=0;
i=1;
int total=0;
while(str[i]!='\0')
{
if(str[i]==str[j])
{
total=(total+1)%10007;
i++;
j++;
}
else
{
if(j==0)
i++;
else
j=0;
}
}
total=(total+n)%10007;
printf("%d\n",total);
}
}