字符串匹配
文章平均质量分 86
wwwiskey
学生
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
KMP算法
#include #include const int LEN = 1000; void prefix(char* mode, int* next) { int j = -1, m = strlen(mode); next[0] = -1; for (int i=1; i<m; i++) { while (j!=-1 && mode[j+1]!=mode[i]) j = next[原创 2012-07-31 11:07:09 · 688 阅读 · 0 评论 -
HDU 3065 病毒侵袭持续中
询问每个模式串在文本传中出现的次数。 文本串中出现的字符不一定都是大写字母,只需要在匹配的时候,对文本串进行特殊处理,将连续的大写字母段当成合法的一个文本串即可。 然后……就是简单的统计了。 #include #include #include #include #include #include using namespace std; int原创 2013-08-07 16:42:50 · 976 阅读 · 0 评论 -
HDU 2222 Keywords Search 【AC自动机模板】
询问有多少个模式串出现在了文本串里面。将模式串插入Trie树中,然后跑一边AC自动机统计一下就哦了。 献上一份模板。 #include #include #include #define MAX_NODE 240005 #define MAX_CHILD 26 using namespace std; class AC_Automaton { public: int c原创 2013-08-06 10:30:49 · 2903 阅读 · 1 评论 -
HDU 2896 病毒侵袭 【AC自动机】
HDU 2222 仅仅求出了和文本串匹配的模式串个数,本题要求求出匹配的模式串的编号。 不同的部分在代码中的注释部分。 #include #include #include #include #include #define MAX_NODE 60005 #define MAX_CHILD 130 using namespace std; vector ans; class原创 2013-08-06 11:55:12 · 1300 阅读 · 0 评论 -
ZOJ 3430 Detect the Virus 【AC自动机+解码】
解码的那些事儿,不多说。 注意解码后的结果各种情况都有,用整数数组存储,char数组会超char类型的范围(这个事最蛋疼的啊)建立自动机的时候不能用0来判断结束。 #include #include #include #include #include #include using namespace std; vector ans; struct AC_Automata原创 2013-08-08 09:57:20 · 1436 阅读 · 0 评论 -
POJ 2778 DNA Sequence【AC自动机+矩阵快速幂】
#include #include #include #include #include #include using namespace std; typedef long long ll; struct AC_Automata { #define Nn 102 #define M 4 int ch[Nn][M], val[Nn], f[Nn], last[原创 2013-08-10 21:36:32 · 3048 阅读 · 2 评论 -
HDU 2825 Wireless Password【AC自动机+DP】
给m个单词,由这m个单词组成的一个新单词(两个单词可以重叠包含)长度为n,且新单词中包含的基本单词数目不少于k个。问这样的新单词共有多少个? m很小,用二进制表示新单词中包含基本单词的情况。 用m个单词建立AC自动机,可以求出所有单词之间相互包含的情况,AC自动机的后缀特性(每个结点的失配边指向新结点,新节点到trie树根的字符串是当前节点字符串的后缀)。 动态规划: f(原创 2013-08-12 14:03:46 · 1207 阅读 · 1 评论 -
POJ 1625 Censored【AC自动机+DP+大数】
给n个字母,构成长度为m的串,总共有n^m种。给p个字符串,问n^m种字符串中不包含(不是子串)这p个字符串的个数。 将p个不能包含的字符串建立AC自动机,每个结点用val值来标记以当前节点为后缀的字符串是否包含非法字符串(p个字符串中的任何一个)。 状态转移方程:f(i, j) += f(i-1, k) f(i, j)表示长度为i的字符串,结尾为字符j,方程j和k的关系可以从自动机中原创 2013-08-11 16:05:08 · 2527 阅读 · 1 评论 -
POJ 3691 DNA repair【AC自动机+DP】
只能说这道题目的数据好强啊,以前写的自动机都是有缺陷的但是可以过题,这次被坑大发了……呜呜 f(i, j)表示长度为i的串,到j状态时需要更改的次数。 f(i, u) = min(f(i, u), f(i-1, j) + (s[i] != k)) u是状态j的子状态。 #include #include #include #include using namespace原创 2013-08-13 17:07:50 · 1112 阅读 · 0 评论
分享