直接上传送门好了,我觉得他分析得非常透彻。

http://972169909-qq-com.iteye.com/blog/1114968

 #include <cstdio>
#include <cstring> const int maxn = + ;
const int MOD = ;
char s[maxn];
int next[maxn], l; void get_next()
{
int k = -, j = ;
next[] = -;
while(j < l)
{
if(k == - || s[k] == s[j])
{
k++;
j++;
next[j] = k;
}
else k = next[k];
}
} int main(void)
{
int T;
scanf("%d", &T);
while(T--)
{
scanf("%d", &l);
scanf("%s", s);
get_next(); int ans = ;
for(int j = ; j < l; ++j)
if(next[j] > && next[j] + != next[j+])
ans = (ans + next[j]) % MOD;
ans = (ans + l + next[l]) % MOD;
printf("%d\n", ans);
} return ;
}

代码君

HDU 3336 (KMP next性质) Count the string的更多相关文章

  1. 【KMP+DP】Count the string

    KMP算法的综合练习 DP很久没写搞了半天才明白.本题结合Next[]的意义以及动态规划考察对KMP算法的掌握. Problem Description It is well known that A ...

  2. hdu 3336 kmp+next数组应用

    分析转自:http://972169909-qq-com.iteye.com/blog/1114968 十分易懂 题意:求字串中[前缀+跟前缀相同的子串]的个数? Sample Input 1 4 a ...

  3. HDU 3336 KMP

    题意:求每一个前缀,跟前缀相同的每个子串. 此题:网上很多都是假程序,不过也AC了,的确我测试几个案例之后的的确确是存在这个问题. 分析:每一个前缀,可以考虑KMP,f失配指针,如何求得它出现了多少次 ...

  4. HDU 3336 Count the string(KMP的Next数组应用+DP)

    Count the string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  5. (KMP)Count the string -- hdu -- 3336

    http://acm.hdu.edu.cn/showproblem.php?pid=3336 Count the string Time Limit: 2000/1000 MS (Java/Other ...

  6. hdu 3336 count the string(KMP+dp)

    题意: 求给定字符串,包含的其前缀的数量. 分析: 就是求所有前缀在字符串出现的次数的和,可以用KMP的性质,以j结尾的串包含的串的数量,就是next[j]结尾串包含前缀的数量再加上自身是前缀,dp[ ...

  7. hdu 3336 Count the string KMP+DP优化

    Count the string Problem Description It is well known that AekdyCoin is good at string problems as w ...

  8. hdu 3336:Count the string(数据结构,串,KMP算法)

    Count the string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  9. HDU 3336 Count the string 查找匹配字符串

    Count the string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

随机推荐

  1. Sponsored Feature: Common Performance Issues in Game Programming

    转自http://www.gamasutra.com/view/feature/132084/sponsored_feature_common_.php?print=1 By Becky Heinem ...

  2. HTML的标签-W3School读后总结

    学习前端知识有一段时间了,前两天想做个博客园的皮肤的静态页面.虽然做完了,但是有很多不如意的地方,反思一下,还是基础不够好,所以现在把html再过一遍.(这个是Xmind生成的图片)

  3. 2005: [Noi2010]能量采集 - BZOJ

    Description 栋栋有一块长方形的地,他在地上种了一种能量植物,这种植物可以采集太阳光的能量.在这些植物采集能量后,栋栋再使用一个能量汇集机器把这些植物采集到的能量汇集到一起. 栋栋的植物种得 ...

  4. CSDN——【低调的草原狼】——Ext4.2学习目录整理

    最近在研究ExtJS,发现CSDN中有个博客中一系列文档非常优秀,但是没有对目录进行整理,在此稍作整理,也为以后自己研究打下一个基础: 原文作者:低调的草原狼 目录:     1.ExtJS4.2学习 ...

  5. VMware vSphere HyperVisor安装过程记录

      作者:sdjnzqr 出处:http://www.cnblogs.com/sdjnzqr/ 版权:本文版权归作者和博客园共有 转载:欢迎转载,但未经作者同意,必须保留此段声明:必须在文章中给出原文 ...

  6. Asp.Net原理Version1.0

    Asp.Net原理Version2.0 Asp.Net原理Version3.0_页面声明周期

  7. 详解HTML5中的<aside>元素与<article>元素

    <aside>元素HTML<aside>元素表示一个页面的一部分, 它的内容跟这个页面的其它内容的关联性不强,或者是没有关联,单独存在.<aside>元素通常显示成 ...

  8. 【转载】C++中结构体的声明和定义

    http://blog.csdn.net/whuslei/article/details/5665289 1  //定义一个结构体,类型为struct Student 2  struct  Stude ...

  9. [unity3d]手游资源热更新策略探讨

    原地址:http://blog.csdn.net/dingxiaowei2013/article/details/20079683 我们学习了如何将资源进行打包.这次就可以用上场了,我们来探讨一下手游 ...

  10. RFID开发笔记 Alien阅读器文档

    1. 开机使用serial connect,完成boot后使用TCP/IP协议与主机通信 2.TagList,是一个活跃标签的列表,这里活跃的含义是在一个间隔里被监听到.如果一个标签之前没有被监听到, ...