
kmp
yzllz001
A programmer
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
KMP算法C代码实现
一、初识KMP 理解KMP算法需要关注2个问题:(请注意:字符串下标从0开始。) 当i指针与j指针失配时: 1、当母串和模式串不匹配时,i指针为什么不需要回溯? 2、当母串和模式串不匹配时,i指针不回溯,那么j指针应该移动到哪? 通过解释第1个问题,我来引出第2个问题。(其实第1个问题,你不明白,不影响你研究第2个问题,你也可以转载 2016-04-14 10:51:52 · 688 阅读 · 0 评论 -
KMP算法小结
KMP算法:1.理解NEXT数组的意义。2.理解模式匹配的过程。3.理解回退的原理(从上一次匹配成功的字符串开始继续匹配)#include #include int next[100000];char ch1[10000], ch2[1000];void getnext(){ int len2 = strlen(ch2 + 1); next[1]原创 2015-07-28 16:14:04 · 400 阅读 · 0 评论 -
HDU 1841: Find the Shortest Common Superstring
!!!#include#include#includeusing namespace std;char a[2000005],b[2000005];int nextd[2000010];void get(char *ch){ int l = strlen(ch); int s = 0,t = -1; nextd[0] = -1; while(s <l) { if(t原创 2015-07-30 15:52:38 · 573 阅读 · 0 评论 -
POJ 2406
DescriptionGiven two strings a and b we define a*b to be their concatenation. For example, if a = "abc" and b = "def" then a*b = "abcdef". If we think of concatenation as multiplication, exponen原创 2016-04-30 11:03:26 · 319 阅读 · 0 评论 -
HDU 2087-剪花布条
HDU 2087KMP算法#include#include#includeusing namespace std;char a[1001],b[1001];int nextd[1001];void gnext(){ int l1=strlen(a+1); int l2=strlen(b+1); int s=1,t=0; while(s<=l2) { i原创 2016-06-30 12:09:07 · 399 阅读 · 0 评论 -
HDU 3336-Count the string
HDU 3336KMP+DP#include #include using namespace std; #define MAX 200005 #define mod 10007 int next[MAX],num[MAX]; char s[MAX]; void get_next() { int i=0,j=-1; next[原创 2016-06-30 12:13:10 · 460 阅读 · 0 评论 -
HDU 1358
DescriptionFor each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, inclusive), we want to know whether the prefix is a periodic string. That is,原创 2016-06-30 12:07:22 · 391 阅读 · 0 评论 -
HDU 1754 I Hate It
线段树入门#include#include#include#define lson rt<<1#define rson (rt<<1)+1using namespace std;int a[1000001];char b[1000001];void build(int l,int r,int rt){ if(l==r) { scanf("%d"原创 2016-04-30 11:09:51 · 292 阅读 · 0 评论 -
POJ 3461 Oulipo
DescriptionThe French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e'. He was a member of the Oulipo group. A quote from the book:Tout avait Pair n原创 2016-04-30 11:07:36 · 387 阅读 · 0 评论 -
HDU 1867:A + B for you again
#include#include#includeusing namespace std;char a[100001],b[100001];int nextd[100001];void get(char *ch){ int s=0,t=-1; nextd[0]=-1; int l=strlen(ch); while(s<l) { if(t==-1||ch[s]==ch[原创 2015-07-30 15:47:20 · 507 阅读 · 0 评论