POJ2406Power Strings[KMP 失配函数]】的更多相关文章

Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 45005   Accepted: 18792 Description Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc" and b = "def" then a*b = "…
Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 39291 Accepted: 16315 Description Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc" and b = "def" then a*b = "abcd…
题目链接:点击进入 事实上就是KMP算法next数组的简单应用.假设我们设这个字符串的最小周期为x 长度为len,那么由next数组的意义,我们知道len-next[len]的值就会等于x.这就是这个题目的关键点. 代码例如以下: #include<iostream> #include<cstdio> #include<cstring> using namespace std; const int maxn=1000000+100; char str[maxn]; in…
Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 31111   Accepted: 12982 Description Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc" and b = "def" then a*b = "…
Period Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 16776   Accepted: 8077 Description For 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…
Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 33163   Accepted: 13784 Description Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc" and b = "def" then a*b = "…
/* Name: hdu--1358--Period Author: 日天大帝 Date: 20/04/17 10:24 Description: 长度/向后移动的位数 = 出现的次数 kmp其实匹配到了第str.size()位,这一位原本是'\0'的, 但是由于里面的递推下一位的关系,这一位其实也是匹配了的: */ #include<iostream> #include<cstring> using namespace std; void getfail(string); ];…
POJ 2406 其实就是一个简单的kmp应用: ans = n % (n - f[n]) == 0 ? n / (n - f[n]) : 1 其中f是失配函数 //#pragma comment(linker, "/STACK:1677721600") #include <map> #include <set> #include <stack> #include <queue> #include <cmath> #inclu…
题意:给出一个字符集和一个字符串和正整数n,问由给定字符集组成的所有长度为n的串中不以给定字符串为连续子串的有多少个? 析:n 实在是太大了,如果小的话,就可以用动态规划做了,所以只能用矩阵快速幂来做了,dp[i][j] 表示匹配完 i 到匹配 j 个有多少种方案,利用矩阵的性质,就可以快速求出长度为 n 的个数,对于匹配的转移,正好可以用KMP的失配函数来转移. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000")…
出处:http://www.cnblogs.com/wuyiqi/archive/2012/01/06/2314078.html kmp next函数 kmp的周期问题,深入了解kmp中next的原理 ----------------------- ----------------------- k    m        x      j       i 由上,next[i]=j,两段红色的字符串相等(两个字符串完全相等),s[k....j]==s[m....i] 设s[x...j]=s[j.…