随笔分类 -  kmp

 
HDU 1358
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1358求某个前缀的周期,用Next求循环节的题目#include #include #include #include using namespace std ;char B[1000005] ;int Next[... 阅读全文
posted @ 2014-05-20 21:35 LegendaryAC 阅读(145) 评论(0) 推荐(0)
HDU 3746
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3746kmp的Nxet数组求字符串循环节例题lenB%(lenB-Next[lenB])==0则其有周期lenB/(lenB-Next[lenB]),其中最小循环节长度是lenB-Next[lenB]#includ... 阅读全文
posted @ 2014-05-20 21:14 LegendaryAC 阅读(380) 评论(0) 推荐(0)
CF 432D
摘要:http://codeforces.com/problemset/problem/432/D在前缀是后缀的前提下,求这个前缀在原串中出现了多少次出现的次数可以用dp求解,前缀是后缀直接用Next判断,较为综合的kmp考察,这题没写出来就是kmp基础不牢,不应该#include #include #i... 阅读全文
posted @ 2014-05-20 20:14 LegendaryAC 阅读(321) 评论(0) 推荐(0)
HDU 3336 Count the string
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3336求字符串的前缀在字符串中一共出现多少次。这个讲解的很清楚,传送门:http://972169909-qq-com.iteye.com/blog/1114968我用的思想是递推,把next数组向右平移一位,转移... 阅读全文
posted @ 2012-05-30 23:27 LegendaryAC 阅读(180) 评论(0) 推荐(0)
HDU 2594 Simpsons’ Hidden Talents
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2594好题,做完之后直接对KMP的理解提升一个档次。主要考察对_next数组含义的理解,之前的理解有点模糊,卡了两个半小时。View Code #include #include #include #include... 阅读全文
posted @ 2012-05-30 17:50 LegendaryAC 阅读(200) 评论(0) 推荐(0)
HDU 1686 Oulipo
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1686求子串个数,可重复,直接上KMP模板View Code #include #include using namespace std ; int n,m;char a[1000002],b[10002];int... 阅读全文
posted @ 2012-05-30 14:22 LegendaryAC 阅读(158) 评论(0) 推荐(0)
KMP
摘要:AB串下标都从1开始,kmp函数返回第一次成功匹配的A串下标,把其中注释去掉可以匹配多个Next[i]表示位置长度为1-i的字符串最多有长度为Next[i]的前缀等于其后缀char A[1000005],B[1000005] ;int Next[1000005],lenA,lenB ;void Ge... 阅读全文
posted @ 2012-05-30 13:59 LegendaryAC 阅读(188) 评论(0) 推荐(0)
HDU 1711 Number Sequence
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1711终于炼化了kmp算法,就算是现在我仍然惊异于字符串匹配居然存在线性时间的算法这种超出了我这种sb认知的东西。自己搞了N久,发现还是没有网上的模板写的好,这里直接收藏了。View Code #include #... 阅读全文
posted @ 2012-05-30 13:45 LegendaryAC 阅读(176) 评论(0) 推荐(0)