关于kmp
  • 板块灌水区
  • 楼主SegmentTree_
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/4/16 22:29
  • 上次更新2024/4/17 13:31:43
查看原帖
关于kmp
716260
SegmentTree_楼主2024/4/16 22:29
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5+5;
string s;
int len, nxt[N], x, mx;
int main(){
	//ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> s;
	len = s.size();
	s = ' ' + s;
	for (int i = 2, j = 0;i <= len;i++){
		while (j && s[j + 1] != s[i]) j = nxt[j];
		if (s[j + 1] == s[i]) ++j;
		nxt[i] = j;
		if (i < len) mx = max(mx, nxt[i]);
	}
	x = nxt[len];
	while (x > mx) x = nxt[x];
	return 0;
} 

这段代码的x是s的最短Border长度吗,是的话,原理是什么

2024/4/16 22:29
加载中...