knuth-morris-pratt
- FIND(X,Y)
- MARRY(X)
FIND(X,Y)
1 2 3 4 5 6 7 8 9 10
| 初始化数组f全部置0用于部分匹配表 MARRY(X) for i=0 to y.size while j>0 and x[j]!=y[i] j=f[j] if x[j]==y[i] j=j+1 if j==x.size sum=sum+1 return sum
|
MARRY(X)
1 2 3 4 5 6 7
| for i=1 to x.size j=f[i] while j>0 and x[j]!=x[i] j=f[j] if x[j]==x[i] f[i+1]=j+1 else f[i+1]=0
|
P2375 [NOI2014]动物园
P3193 [HNOI2008]GT考试