#include
#include
#include
#define N 1000005
int next[N];
char s[N];
using namespace std;
void getnext(char s[])
{
int j=-1,i=0,len;
next[0]=-1;
len=strlen(s);
while(i<=len)
{
if(j==-1||s[i]...
分类:
其他好文 时间:
2014-10-21 01:06:37
阅读次数:
235
next数组表示的是,最长前缀和后缀相等的长度。
#include
#include
#include
#include
using namespace std;
const int N=1000000;
int next[N];
char s[N],t[N];
/*********KMP小结**********/
//求next数组
void getNext(int lt)
{
...
分类:
其他好文 时间:
2014-10-20 23:26:53
阅读次数:
294
前言虽从事企业应用的设计与开发,闲暇之时,还是偶尔涉猎数学和算法的东西,本篇根据个人角度来写一点关于KMP串匹配的东西,一方面向伟人致敬,另一方面也是练练手,头脑风暴背景目标串: T(1…..n)模式串: P(1…..m)输出:搜索P在T中的位置 s,令 T(s…s+m-1) === P(1…m)例...
分类:
编程语言 时间:
2014-10-20 23:13:12
阅读次数:
176
题目链接:http://poj.org/problem?id=3461思路: 字符串匹配问题,使用KMP算法解决。代码:#include char T[1000005], W[10005];int Next[10005];int Len_T, Len_W;void GetNext( ){ ...
分类:
其他好文 时间:
2014-10-20 21:05:04
阅读次数:
138
KMP算法
BF算法
BF算法就是我们最基本的求解字符串匹配的算法,算法的时间复杂度为O(M*N),空间复杂度为O(1),具体过程如下:
串
第一次
第二次
第三次
第四次
模式串S[i]
abcababc
abcababc
abcababc
abcababc
匹配串T[j]
...
分类:
编程语言 时间:
2014-10-20 17:26:30
阅读次数:
233
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3689黄老师说得对,题目只有做wa了才会有收获,才会有提高。题意:一个猴子敲键盘,键盘上有n个键,猴子敲第i个键的概率是p[i],问敲m次后形成的字符串里出现给定串的概率是多少。这实际上就跟那个ac自动机...
分类:
其他好文 时间:
2014-10-20 09:52:51
阅读次数:
284
#include
#include
#include
#define N 1000010
using namespace std;
char s[N];
int next[N];
void getnext(char s[])
{
int j=-1,i=0,len;
next[0]=-1;
len=strlen(s);
while(i<=len)
{
if(j==-1||...
分类:
其他好文 时间:
2014-10-19 23:20:35
阅读次数:
330
Period
Time Limit: 3000MS
Memory Limit: 30000K
Total Submissions: 13511
Accepted: 6368
Description
For each prefix of a given string S with N characters (each character...
分类:
其他好文 时间:
2014-10-19 21:30:13
阅读次数:
233
Power Strings
Time Limit: 3000MS
Memory Limit: 65536K
Total Submissions: 33178
Accepted: 13792
Description
Given two strings a and b we define a*b to be their concatena...
分类:
其他好文 时间:
2014-10-19 21:29:13
阅读次数:
204
对于一个字符串S,长度为L,如果由长度为len的字符串s(字符串s的最小循环节是其本身)循环k次构成,那么字符串s就是字符串S的最小循环节那么字符串有个很重要的性质和KMP挂钩,即 i - next[i] 为字符串s的长度 i%(i - next[i]) ==0证明:字符串S由s循环k次构成,那么有...
分类:
其他好文 时间:
2014-10-19 21:09:09
阅读次数:
195