![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
KMP
Richard__Luan
这个作者很懒,什么都没留下…
展开
-
kmp模板
KMP是一种匹配算法,其优化了匹配过程,效率可以达到O(n+m) KMP有两个过程,第一个是求主串next数组,相当于自己匹配自己,求出最长公共前后缀 第二个是把模式串放在主串上匹配 求next数组 memset(nxt,0,sizeof(nxt)); for(int i=1;i<b.length();i++) { int j=nxt[i]; while(j&&...原创 2018-07-21 14:13:35 · 139 阅读 · 0 评论 -
BZOJ【3942】[Usaco2015 Feb]Censoring
Kmp 我们需要开一个栈,记录这个点匹配到主串的哪个位置和字符,如果匹配就减去主串长度 这样做显然是对的 AC Code #include&amp;amp;lt;cstdio&amp;amp;gt; #include&amp;amp;lt;iostream&amp;amp;gt; #include&amp;amp;lt;cstring&amp;amp;gt; using namespace std;原创 2018-09-19 20:48:01 · 146 阅读 · 0 评论