![](https://img-blog.csdnimg.cn/20201014180756923.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
KMP
HOrchard
这个作者很懒,什么都没留下…
展开
-
HDU5510(Bazinga)(KMP)
Bazinga Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 6280 Accepted Submission(s): 1927 Problem Description Ladies and gentlem原创 2018-01-17 20:23:45 · 294 阅读 · 0 评论 -
HDU1358 Period(KMP)
给出一个字符串,问这个字符串的所有前缀是否油循环节,并且说出有几个循环节构成 KMP算法可以的next数组可以用来计算循环节。 #include #include #include using namespace std; const int N=1000005; int nextt[N]; char str[N]; void makenextt(char p[],int len) {原创 2018-03-11 20:09:53 · 167 阅读 · 0 评论 -
POJ2752 Seek the Name, Seek the Fame(KMP)
题目给出一个字符串,求这个字符串所有的相同前后缀的长度。 KMP的next数组的应用,KMP的next数组在失配时向前跳转的下标,所以从最后一个字符开始访问,不停的向前跳转,每次的next数组值就是答案。因为当最后一个字符开始向前跳转的时候,就已经出现了第一个合法的前后缀,第二次再次跳转的时候,实际上就是在第一次出现的前后缀里在寻找合法的前后缀。。。以此类推,可以有第三次,第四次跳转。 #in原创 2018-03-12 18:15:33 · 190 阅读 · 0 评论 -
HDU3336 Count the string(KMP+DP)
计算字符串的每个前缀在字符串里出现的次数。 一个KMP+DP,在KMP的next数组中,next[i]=j就表示在前i个字符串当中,从前1到j的j长度字符字串和i-j+1到i的j长度的字符字串相等。那么,每一个位置的字符只要继承它的next[i]位置的数量,再加一就是它当前的数量了。 #include #include #include using namespace std; cons原创 2018-03-13 20:28:39 · 170 阅读 · 0 评论 -
HDU2594 Simpsons’ Hidden Talents(KMP)
给两个字符串,找到两个字符串的最长相同后缀和前缀。 KMP,把两个字符串连接起来,最后一个字符的next数组内容就是最长的长度。 两个字符串之间要插入一个其他字符。 #include #include #include #include using namespace std; const int N=50005; char str1[N]; char str2[N],str[N*1原创 2018-03-13 21:18:12 · 174 阅读 · 0 评论 -
FZU 1901 Period II(KMP)
又是KMP中next数组的应用。 还是判断最大相同前后缀,然后不停的向后跳转,直到next数组为0为止。 #include #include #include #include using namespace std; const int N=1e6+5; char str[N]; int nextt[N]; int ans[N]; void makenextt(char str[]原创 2018-03-22 11:23:16 · 233 阅读 · 1 评论