随笔分类 -  字符串--KMP

A little hard to understand!
摘要:原题链接:http://poj.org/problem?id=2406分析:求最小周期。 1 #include 2 #include 3 #include 4 #include 5 #define maxn 1000005 6 using namespace std; 7 char s[maxn]; 8 int next[maxn],len; 9 void get_next()10 {11 int i=0,j=-1;len=strlen(s);12 next[0]=-1;13 while(i<len)14 {15 if(j==-1||s[i]==... 阅读全文
posted @ 2013-08-09 09:21 EtheGreat 阅读(231) 评论(0) 推荐(0)
摘要:原题链接:http://poj.org/problem?id=2752分析:no! 1 #include 2 #include 3 #include 4 #define maxn 400005 5 using namespace std; 6 char s[maxn]; 7 int len,next[maxn],ans[maxn]; 8 void get_next() 9 {10 int i=0,j=-1;len=strlen(s);11 next[0]=-1;12 while(i=1;j--)31 printf("%d ",ans[j]);32 ... 阅读全文
posted @ 2013-08-09 01:09 EtheGreat 阅读(158) 评论(0) 推荐(0)
摘要:原题链接:http://poj.org/problem?id=3461分析:求一个串在另一个串中出现的次数,显然用KMP可以解决。 1 #include 2 #include 3 #include 4 #define maxn1 10005 5 #define maxn2 1000005 6 using namespace std; 7 char s[maxn1],t[maxn2]; 8 int next[maxn1],sum,len1,len2; 9 void get_next()10 {11 int i,j;len1=strlen(s);12 next[0]=-1;13 ... 阅读全文
posted @ 2013-08-09 00:21 EtheGreat 阅读(232) 评论(0) 推荐(0)