文章分类 -  Algorithm

后缀数组求最长重复子串
摘要:对于类似从给定的文本中,查找其中最长的重复子字符串的问题,可以采用“后缀数组”来高效地完成此任务。后缀数组使用文本本身和n个附加指针(与文本数组相应的指针数组)来表示输入文本中的n个字符的每个子字符串。 首先,如果输入字符串存储在c[0..n-1]中,那么就可以使用类似于下面的代码比较每对子字符串: maxlen = -1 for i = [0, n) for j = (i... 阅读全文

posted @ 2010-08-17 18:41 dyh333 阅读(1880) 评论(5) 推荐(0)

KMP
摘要:#include <stdio.h>#include <stdlib.h>#include <string.h>#define MAX_S 101 /*主串的长度最大值为100*/#define MAX_P 21 /*模式串的长度最大值为20*/char s[MAX_S],p[MAX_P]; /*s为主串,p为模式串*/int nextv[MAX_P]; /*p... 阅读全文

posted @ 2010-08-17 18:41 dyh333 阅读(139) 评论(0) 推荐(0)

最长重复子串
摘要:#include <stdio.h>#include <stdlib.h>#define BUF_MAX 1000int index; //子串起始位置int len;//子串长度void str_search(const char *str){int i=0,j;while(str[i]!='\0') ++i;int strlen=i;for(i=strlen/2;i&g... 阅读全文

posted @ 2010-08-17 18:40 dyh333 阅读(114) 评论(0) 推荐(0)

导航