题目链接: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
#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
#include
#include
#include
#define N 10000001
using namespace std;
char s[N],s1[N];
int next[N];
void getnext(char s1[])
{
int j=-1,i=0,len;
next[0]=-1;
len=strlen(s1);
while(i<len)
{
if(j==-1|...
分类:
其他好文 时间:
2014-10-19 14:22:00
阅读次数:
175
判断一个字符串在另一字符串中是否出现过 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 int f[ 15000]; 8 void getfill(string s) 9 {10 ...
分类:
编程语言 时间:
2014-10-19 01:13:02
阅读次数:
179
Binary String Matching
时间限制:3000 ms | 内存限制:65535 KB
难度:3
描述Given two strings A and B, whose alphabet consist only ‘0’ and ‘1’. Your task is only to tell how many times does A appear as ...
分类:
编程语言 时间:
2014-10-18 09:50:53
阅读次数:
238
问题背景是找到原串中能够与给定串完全匹配的部分,最容易想到的双重循环比对当然不行(时间复杂度太高),最经典的解法就是KMP算法,先构造跳转表(next表),再比对,避免主串上的回溯,以节省时间。KMP算法比较难理解,本文主要对其核心next函数作以解析。
分类:
编程语言 时间:
2014-10-18 00:37:36
阅读次数:
229
题目大意:给定长度为m的数字串s,求不包含子串s的长度为n的数字串的数量
n
我们不考虑这个 令f[i][j]为长度为i的数字串中最后j位与s中的前j位匹配的方案数
比如当s为12312时 f[i][3]表示长度为i,以123结尾且不包含子串”12312“的方案数
a[x][y]为f[i-1][x]转移至f[i][y]的方案数
换句话说(可能描述不清楚) a[x][y]为s的长度为x的前...
分类:
编程语言 时间:
2014-10-17 18:54:11
阅读次数:
304
KMP算法详解如果机房马上要关门了,或者你急着要和MM约会,请直接跳到第六个自然段。我们这里说的KMP不是拿来放电影的(虽然我很喜欢这个软件),而是一种算法。KMP算法是拿来处理字符串匹配的。换句话说,给你两个字符串,你需要回答,B串是否是A串的子串(A串是否包含B串)。比如,字符串A="I'm m...
分类:
其他好文 时间:
2014-10-17 18:30:54
阅读次数:
148
算法细节详见点击打开链接和点击打开链接#include #include #define N 7#define M 15void showpset(int* a);void cal_pset(char* a, int* p,int n);int KMP(char* a,char* b,int* P)...
分类:
编程语言 时间:
2014-10-17 00:26:43
阅读次数:
260