好久没有写过KMP了,今天写个KMP练练手.此题就是枚举左端点暴力,用KMP做到O(n^2) #include<cstdio> #include<cstring> using namespace std ; + ; char BUF_OF_T [ MAXL ] ; int BUF_OF_F [ MAXL ] ; class KMP { private : char * T ; int * F ; public : KMP ( char * S ) { const int L = s…
要点 本题使用\(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…
KMP 我似乎复杂度写的不对... 因为位置相同只算一次,后缀数组什么的都不管用了,我们就暴力kmp,但是我写的是暴力跳...竟然过了...我写bzoj3670才发现... #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ; int n, k, ans; int nxt[N]; char s[N]; void kmp(char *s, int len, int *nx…