首页 技术 正文
技术 2022年11月14日
0 收藏 626 点赞 4,901 浏览 729 个字

http://www.lydsy.com/JudgeOnline/problem.php?id=3676

题意:给一个串求回文串×出现次数的最大值。(|S|<=300000)

#include <bits/stdc++.h>
using namespace std;
const int N=300005;
struct E {
int f[N], c[N][26], l[N], last, s[N], n, cnt[N], tot;
E() { f[0]=1; f[1]=0; l[1]=-1; n=0; s[0]=-1; tot=1; last=0; }
int find(int x) { while(s[n-l[x]-1]!=s[n]) x=f[x]; return x; }
void add(int ch) {
s[++n]=ch;
int x=find(last);
if(!c[x][ch]) {
int y=++tot;
f[y]=c[find(f[x])][ch];
c[x][ch]=y;
l[y]=l[x]+2;
}
cnt[last=c[x][ch]]++;
}
long long getans() {
for(int i=tot; i>=0; --i) cnt[f[i]]+=cnt[i];
long long ans=0;
for(int i=0; i<=tot; ++i) ans=max(ans, 1ll*cnt[i]*l[i]);
return ans;
}
}a;
char st[N], *s=st;
int main() {
scanf("%s", s);
for(; *s; ++s) a.add(*s-'a');
printf("%lld\n", a.getans());
return 0;
}

  

裸的回文自动机。。注意更新每个节点的时候是可以直接从后向前更新的。。(因为加点顺序本来就是拓扑序。。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,085
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,560
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,409
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,182
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,819
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,902