字符串 -------- KMP
SolarDomo
每天都被头像萌醒
展开
-
POJ 1961 KMP
题目链接题意: 求所有可以 表示成 (S)^K的前缀 输出前缀位置 和 k的最大值代码:#include <cstdio> #include <iostream> #include <vector> #include <cstring> #include <algorithm> #define sf scanf #define pf printf using namespace std; const原创 2016-08-08 13:09:38 · 204 阅读 · 0 评论 -
POJ 2752 KMP 待AC
题目链接求相等前后缀长度代码:#include <cstdio> #include <iostream> #include <vector> #include <cstring> #include <algorithm> #define sf scanf #define pf printf using namespace std; const int maxn = 400000 + 50; char原创 2016-08-08 14:02:32 · 233 阅读 · 0 评论 -
POJ 3080 Blue Jeans 字典树
题目链接题意:给N个文本串 找到在一个在N个文本串中都出现的最长的字典序最小的字串本来找的是KMP 的题 想来半天都不知道怎么用KMP搞 之后发现可以 将每个串的后缀都加入一颗字典树中 字典树中每个节点的value表示一个状态 即 这个串在哪几个序列中出现过 最后在树上深搜 按A C G T 的顺序搜索 最后在逆这树向上打印文本时间复杂度: 一个串有len个后缀 将一个长度为n的串加入原创 2016-08-08 15:08:35 · 252 阅读 · 0 评论 -
POJ 2406 Power Strings KMP
题目链接题意:问串S 最多能表示成多少个串的重复 输出重复的最大值代码:#include <cstdio> #include <iostream> #include <cstring> using namespace std; const int maxn = 1000000 + 5; int NEXT[maxn]; char str[maxn]; int main(){ while( sc原创 2016-08-08 13:11:50 · 212 阅读 · 0 评论 -
KMP 模板
测试题目:const int maxn = 100; char s[maxn],p[maxn]; int fail[maxn]; /* p为模式串 ** f为保存失配边的数组 ** */ void getFail(char* p,int* f){ int m = strlen(p); f[0] = 0; f[1] = 0; for(int i = 1;i < m;++i)原创 2016-09-26 17:52:59 · 216 阅读 · 0 评论