摘要:
关于KMP的最短循环节、循环周期,请戳:http://www.cnblogs.com/chenxiwenruo/p/3546457.html(KMP模板,最小循环节)POJ 2406 Power Strings题意:给一个字符串,问这个字符串是否能由另一个字符串重复R次得到,求R的最大值。#include #include #include /*题意:给一个字符串,问这个字符串是否能由另一个字符串重复R次得到,求R的最大值。*/using namespace std;const int maxn=1000005;int next[maxn];char str[maxn];void getnex 阅读全文
posted @ 2014-02-12 21:48
辰曦~文若
阅读(284)
评论(0)
推荐(0)
摘要:
http://blog.sina.com.cn/s/blog_74e20d8901010pwp.html我采用的是方法三。注意:当长度相同时,取字典序最小的。#include #include #include #include /*http://blog.sina.com.cn/s/blog_74e20d8901010pwp.html我采用的是方法三。注意:当长度相同时,取字典序最小的。*/using namespace std;const int maxn=4005;char str[maxn][210];int n;int minlen; //n个字符串中最短的长度int id; //长 阅读全文
posted @ 2014-02-12 21:31
辰曦~文若
阅读(244)
评论(0)
推荐(0)
摘要:
(可以转载,但请注明出处!)下面是有关学习KMP的参考网站http://blog.csdn.net/yaochunnian/article/details/7059486http://blog.csdn.net/v_JULY_v/article/details/6111565http://blog.csdn.net/v_JULY_v/article/details/6545192http://blog.csdn.net/oneil_sally/article/details/3440784http://billhoo.blog.51cto.com/2337751/411486先说说next数组 阅读全文
posted @ 2014-02-12 18:34
辰曦~文若
阅读(7454)
评论(0)
推荐(3)
摘要:
给一个字符串S,求出所有前缀,使得这个前缀也正好是S的后缀。升序输出所有情况前缀的长度。KMP中的next[i]的意义就是:前面长度为i的子串的前缀和后缀的最大匹配长度。明白了next[i],那么这道题就很容易做了#include #include #include #include using namespace std;const int maxn=400005;char str[maxn];int next[maxn];int n;int ans[maxn];void getnext(char *str,int len){ next[0]=-1; int i=0,j=-1; ... 阅读全文
posted @ 2014-02-12 14:48
辰曦~文若
阅读(226)
评论(0)
推荐(0)

浙公网安备 33010602011771号