随笔分类 -  KMP

摘要:题目链接题意: 输入两个字符串,计算二串在一串中出现的次数。 裸裸的KMP,参考刘汝佳《算法竞赛入门经典训练指南》 P212 或数据结构。代码如下://light oj 1255 - Substring Frequency (KMP)//2013-05-13-19.12#include #include const int maxn = 1000006;char a[maxn];char b[maxn];int f[maxn];void getfail(){ int l = strlen(b); f[0] = 0; f[1] = 0; for (int i = ... 阅读全文
posted @ 2013-05-13 19:10 xindoo 阅读(142) 评论(0) 推荐(0)
摘要:题目链接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, for each i (2 1 (if there is one) such that the prefix of S with length i can be written as AK ,th. 阅读全文
posted @ 2013-04-06 14:57 xindoo 阅读(260) 评论(0) 推荐(0)
摘要:Problem DescriptionGiven two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], ...... , b[M] (1 int n, m;int a[1000005];int b[10005];int f[10005];void getfail(){ f[0] = 0; f[1] = 0; for (int i = 1; i < m; i++) { int j = f[i]; while (j && b[i] != b[j]) ... 阅读全文
posted @ 2013-02-06 21:29 xindoo 阅读(122) 评论(0) 推荐(0)