![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
KMP
KLFTESPACE
这个作者很懒,什么都没留下…
展开
-
从头到尾彻底理解KMP
从头到尾彻底理解KMP 作者:July 时间:最初写于2011年12月,2014年7月21日晚10点 全部删除重写成此文,随后的半个多月不断反复改进。后收录于新书《编程之法:面试和算法心得》第4.4节中。 1. 引言 本KMP原文最初写于2年多前的2011年12月,因当时初次接触KMP,思路混乱导致写也写得混乱。所以一直想找机会重新写下KMP,但苦于一...转载 2018-07-20 22:32:15 · 851 阅读 · 0 评论 -
Period HDU - 1358
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> using namespace std; const int N = 1e6+5; int nxt[N]; int cnt = 0; char s1[N],...原创 2019-08-13 10:00:23 · 76 阅读 · 0 评论 -
Cyclic Nacklace HDU - 3746
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> using namespace std; const int N = 1e6+5; int nxt[N]; int cnt = 0; char s1[N],...原创 2019-08-12 23:18:26 · 144 阅读 · 0 评论 -
Oulipo HDU - 1686
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> using namespace std; const int N = 1e6+5; int nxt[N]; int cnt = 0; char s1[N],...原创 2019-08-12 23:17:16 · 90 阅读 · 0 评论 -
剪花布条 HDU - 2087
刚开始TLE了,是因为找到符合的字符串位置后,j = i+1了...是我蠢了..应该是j = 0;即 模式串向后一模式串个 长度位.... 后来 WA...怎么看都没问题...然后发现cnt每次都没初始为0..... #include<iostream> #include<cstdio> #include<cstring> #include<cma...原创 2019-08-12 23:15:40 · 93 阅读 · 0 评论 -
Number Sequence HDU - 1711
KMP模板 TLE了 输入输出换成标准输入输出AC了... #include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> using namespace std; const int N = 1e6+5; in...原创 2019-08-11 22:51:58 · 157 阅读 · 0 评论 -
Simpsons’ Hidden Talents HDU - 2594
有一种是直接将两个合并,getnext得到前后缀最长匹配字段即可,但是要注意长度小于两个字符串长度 另一种办法是得到一个字符模板串的next数组,然后 对另一字符串进行匹配,直至字符串末尾,若正在匹配中的模板串下标值不为0,说明可匹配,输出即可 #include<iostream> #include<cstdio> #include<cstring> ...原创 2019-08-14 15:53:23 · 183 阅读 · 0 评论 -
Blue Jeans POJ - 3080
#include<iostream> #include<cstdio> #include<string.h> #include<cmath> #include<cstdlib> using namespace std; const int N = 1e3+5; int nxt[N]; int cnt = 0; string s[1...原创 2019-08-14 12:34:52 · 93 阅读 · 0 评论 -
Seek the Name, Seek the Fame POJ - 2752
//刚开始数组开的太大了1e6,OLE了,, 后来看错了开的太小4*1e4...RE.。。。后来发现题目要求4*1e5.。。AC //字符串s的前next[i]长度的字符和后next[i]长度的字符是相同的 #include<iostream> #include<cstdio> #include<cstring> #include<cmath&g...原创 2019-08-13 22:46:21 · 98 阅读 · 0 评论 -
Power Strings POJ - 2406
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> using namespace std; const int N = 1e6+5; int nxt[N]; int cnt = 0; char s1[N],...原创 2019-08-13 20:50:12 · 86 阅读 · 0 评论 -
Theme Section HDU - 4763
//用next[len] 可找到EAEBE的前后缀即E,然后再中间找符合EAEBE的前后缀(前后缀可根据中间查找情况进行缩略即继续查找E的前后缀),需要和已定前后缀间隔一倍E的距离,以防出现EEBE或EAEE的情况 #include<iostream> #include<cstdio> #include<cstdlib> #include<cstri...原创 2019-09-14 23:02:35 · 125 阅读 · 0 评论