要点 本题使用\(O(n^2)\)的算法 外层枚举左端点,内层一直kmp到结尾,中间遇到合法的就ans++ 如果是acccca这种数据直接kmp过程顺手判断即可:但是aaa这种数据,j = 2,实际判断是不合法的,也就是说,其实只要Next里有合法的即本串合法,因此多开Num数组记录 #include <cstdio> #include <cstring> #define min(a, b) a > b ? b : a const int maxn = 15e3 + 5, I…
poj2406 Power Strings(kmp) 给出一个字符串,问这个字符串是一个字符串重复几次.要求最大化重复次数. 若当前字符串为S,用kmp匹配'\0'+S和S即可. #include <cstdio> #include <cstring> using namespace std; const int maxn=2e6+5; char s1[maxn], s2[maxn]; int n1, n2, nxt[maxn], ans; int main(){ while (~…
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 = "abcdef". If we think of concatenation as multiplication, exponentiation by a non-negative inte…
Description In whiteblack on blackwhite is written the utterance that has been censored by the Ministry of Truth. Its author has already disappeared along with his whole history, and now, while Big Brother is watching somebody else, you, as an ordina…