kmp
lj_acm
这个作者很懒,什么都没留下…
展开
-
hdu 4300
字符串匹配。kmp. #include #include #include 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原创 2012-12-27 09:34:18 · 511 阅读 · 0 评论 -
hdu 2203
Kmp初级应用,不解释 说一下失配函数的求解,其中的j其实既维护了改进前的next,又维护了改进后的next //kmp #include #include #include using namespace std; const int maxn=2*100000+10; char s1[maxn],s2[maxn]; int nextv[maxn]; int len1,len2;原创 2013-01-31 11:41:47 · 335 阅读 · 0 评论 -
poj 2752
KMP简单应用,利用next,一个一个确定是否和后缀匹配 #include #include #include using namespace std; const int maxn=400000+10; char s[maxn]; int next[maxn]; int amount[maxn]; int main() { while(~scanf("%s",s)) {原创 2013-04-08 21:04:44 · 986 阅读 · 0 评论 -
poj 2406
KMP的应用 如果串s有s(1)循环得到,那么s(1~len-1)一定与s(2~len)匹配,并且len-2+1一定是1的倍数,同理如果由s(1~2),s(1~3)......是一样的道理,但肯定不会这么一个一个枚举,可知可由kmp中的next[]来枚举,减小时间复杂度 #include #include #include using namespace std; const int原创 2013-04-17 21:31:12 · 671 阅读 · 0 评论