HZOJ 匹配

Hash/KMP裸题,并不想写什么,只是复习一下KMP吧。

 1 void get_n()
 2 {
 3     next[1]=0;
 4     int j=0;
 5     for(int i=2;i<=lt;i++)
 6     {
 7         while(j>0 && t[i]!=t[j+1])j=next[j];
 8         if(t[i]==t[j+1])j++;
 9         next[i]=j;
10     }
11 }
 1 for(int i=1,j=0;i<=ls;i++)
 2     {
 3         while(j>0 && (j==lt || s[i]!=t[j+1]))j=next[j];
 4         if(s[i]==t[j+1])j++;
 5         
 6         stack[++top]=i;
 7         loc[top]=j;
 8         if(j==lt)
 9         {
10             top-=lt;
11             j=loc[top];
12         }
13     }

猜你喜欢

转载自www.cnblogs.com/Al-Ca/p/11247989.html
今日推荐