随笔分类 -  kmp

摘要:KMP的应用如果串s有s(1)循环得到,那么s(1~len-1)一定与s(2~len)匹配,并且len-2+1一定是1的倍数,同理如果由s(1~2),s(1~3)......是一样的道理,但肯定不会这么一个一个枚举,可知可由kmp中的next[]来枚举,减小时间复杂度#include <iostream> #include <cstdio> #include <cstring> using namespace std; const int maxn=1000000+10; char s[maxn]; int next[maxn]; void getNext( 阅读全文
posted @ 2013-04-17 21:31 LJ_COME!!!!! 阅读(108) 评论(0) 推荐(0)
摘要:KMP简单应用,利用next,一个一个确定是否和后缀匹配#include <iostream> #include <cstdio> #include <cstring> using namespace std; const int maxn=400000+10; char s[maxn]; int next[maxn]; int amount[maxn]; int main() { while(~scanf("%s",s)) { int len=strlen(s); int i=0,j=-1; next[0]=-1; ... 阅读全文
posted @ 2013-04-08 21:04 LJ_COME!!!!! 阅读(107) 评论(0) 推荐(0)
摘要:Kmp初级应用,不解释说一下失配函数的求解,其中的j其实既维护了改进前的next,又维护了改进后的next//kmp #include <iostream> #include <cstdio> #include <string.h> using namespace std; const int maxn=2*100000+10; char s1[maxn],s2[maxn]; int nextv[maxn]; int len1,len2; void getNext() { int i=0,j=-1; nextv[0]=-1; while(i<len2- 阅读全文
posted @ 2013-01-31 11:41 LJ_COME!!!!! 阅读(126) 评论(0) 推荐(0)
摘要:字符串匹配。kmp.#include <iostream> #include <stdio.h> #include <string.h> using namespace std; const int maxn=100010; char tran[26],s[maxn]; int next[maxn]; void getv(char * t)//求失配函数 { int i,j;strlen int m=(t); next[0]=-1; i=0;j=-1; while(i<m-1) { if(j==-1||t[i]==t[j]) { j++;i++; if 阅读全文
posted @ 2012-12-27 09:34 LJ_COME!!!!! 阅读(106) 评论(0) 推荐(0)