![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
字符串
文章平均质量分 67
acraz
这个作者很懒,什么都没留下…
展开
-
HDU 2896 病毒侵袭(AC自动机)
AC自动机水题 #include #include #include #include #include using namespace std; struct node{ int tag; node *fail; node *son[128]; }; node word[500*200+5]; node *root; setans;//set来存储病毒编号 int e =原创 2015-04-24 22:41:47 · 382 阅读 · 0 评论 -
HDU 2222 Keywords Search(AC自动机)
AC自动机模板题 #include #include #include #include using namespace std; struct node{ int count; //记录以此为终点的单词的个数 node *fail; node *son[26]; }; queueq; node word[500010]; int e; char str[1000005];原创 2015-04-24 20:54:03 · 334 阅读 · 0 评论 -
KMP字符串匹配算法
KMP算法核心思想是:充分利用已成功匹配的信息来进行接下来的匹配。 主要是 nxt 数组的应用。 下面来说说 nxt 数组意义: (1)nxt[0]= -1 (2)nxt[i]=k 表示模式串s[0,...,k-1]与s[i-k,...i-1]相同且最长 接下来考虑一下 nxt 数组的求法。 假设我们已经知道了 nxt [0,1,...,k],,模式串为s ,现在求 nxt[k原创 2015-08-13 16:19:24 · 241 阅读 · 0 评论 -
POJ 2752 Seek the Name, Seek the Fame(KMP)
理解好nxt数组后这个题目不难 题目让求所有原串前后缀,前后缀就是既是前缀也是后缀的字符串。 nxt[len]指第len+1个字符匹配不上后要跳转的字符,那么以nxt[len]-1为结尾的前缀一定是该字符串的后缀, 然后以nxt[nxt[len]]-1为结尾的前缀也一定是该字符串的后缀,依次我们就可以找到所有前后缀了,,最后不要加上原串本身。 #pragma warning(disable原创 2015-08-14 17:48:04 · 189 阅读 · 0 评论 -
POJ 2406 Power Strings(KMP求最小循环节)
先简单介绍一下KMP算法利用 nxt 数组求最小循环节的原理: 假设图中的黑色是原来的字符串,现在要求最小循环节,对于nxt[len]来说指的是图中蓝色和黄色的长度,而且蓝色和黄色是相等的, 那么绿色和紫色也是相等的,,对比原串可知紫色跟粉色是相同的子串,那么绿色跟粉色相同,然后对比蓝色跟黄色可知红色跟粉色相同,对比原串,红色跟棕色相同,那么棕色跟粉色相同,不断重复此过程可知若此字符串原创 2015-08-14 16:20:07 · 1449 阅读 · 0 评论 -
POJ 1961 Period(KMP最小循环节)
不懂如何用nxt数组求最小循环节的看这里 #pragma warning(disable:4996) #include #include using namespace std; char s[1000005]; int nxt[1000005]; void get_nxt(){ int len = strlen(s); int i = 0, j = -1; nxt[0]原创 2015-08-14 16:45:36 · 338 阅读 · 0 评论 -
HDU 5459 Jesus Is Here(DP)
DP记录答案,更新DP的时候要用到每个cff到其字符串末尾的长度和pos,以及每个cff到其字符串开头的长度和,然后记录一下每个字符串中cff的个数cnt,和字符串长度len,然后乱搞一下就成了。 #pragma warning(disable:4996) #include #include #include #include #include #include using name原创 2015-09-19 20:03:35 · 358 阅读 · 0 评论 -
POJ 1159 Palindrome(区间dp)
dp[i][j]表示s[i,...,j]至少添加几个字符变成回文,转移方程为 if (s[i] == s[j]) { dp[i][j] = dp[i + 1][j - 1]; } else { dp[i][j] = min(dp[i + 1][j], dp[i][j - 1]) + 1; } 注意一下i和j的更新顺序就好了。 然后MLE了一下,改为滚动数组就AC了。 #pra原创 2015-09-21 16:18:01 · 307 阅读 · 0 评论