标签:inpu ane problem code character 等于 main 计算 mat
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
1 #include <stdio.h> 2 #include <string.h> 3 4 char s[200100]; 5 int next_[200100],n; 6 void getnext() 7 { 8 int i = 0, j = -1; 9 next_[0] = -1; 10 while (i < n){ 11 if (j == -1 || s[i] == s[j]) 12 next_[++ i] = ++ j; 13 else 14 j = next_[j]; 15 } 16 } 17 int main() 18 { 19 int i,t,sum; 20 scanf("%d",&t); 21 while (t --) 22 { 23 scanf("%d",&n); 24 scanf("%s",s); 25 getnext(); 26 sum = n; // 首先可以确定的数量为n(每一个长度的前缀) 27 for (i = 1; i <= n; i ++) 28 { 29 if (next_[i] > 0) sum ++; // next[i]不等于0 说明此位置出现与前缀相同的子串 30 sum %= 10007; 31 } 32 printf("%d\n",sum); 33 } 34 return 0; 35 }
标签:inpu ane problem code character 等于 main 计算 mat
原文地址:http://www.cnblogs.com/yoke/p/6920651.html