随笔分类 - KMP
摘要:由于next[i]保存的是前i-1个字符中最大的重复子序列,那么i-next[i]就是循环节。#include#include#includeusing namespace std;int next[1000100];void getnext(char *str){ int j,k; memset(next,0,sizeof(next)); j=0; k=-1; next[0]=-1; while(str[j]) { if(k==-1 || str[j]==str[k]) next[++j]=++k; ...
阅读全文
摘要:#include#include#includeusing namespace std;int next[10010];void getNext(char *str){int j,k;memset(next,0,sizeof(next));j=0;k=-1;next[0]=-1;while(str[j]){if(k==-1 || str[j]==str[k])next[++j]=++k;elsek=next[k];}}int KMP(char *s,char *t){ getNext(t); int i,j,k; i=j=0; int num=0; while(s...
阅读全文

浙公网安备 33010602011771号