博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
回文树学习笔记
阅读量:6972 次
发布时间:2019-06-27

本文共 1103 字,大约阅读时间需要 3 分钟。

作为一枚懒人我怎么可能自己写那咕咕咕

这个挺好哒

然后回文树实际是可以可持久化哒(什么不能啊/xyx)

我们可以把get_fail那一部分用数组存下来,然后可持久化这个数组即可

就先不仔细研究这个玩意了吧咕咕咕

模板()

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;int n,fail[300100],son[300100][30],ans[300100],len[300100],cnt,last;long long Ans;char s[300100];inline void new_node(int x){len[++cnt]=x;ans[cnt]=0;}inline int get_fail(int x,int n){ while(s[n]!=s[n-len[x]-1])x=fail[x]; return x;}inline void build(){ for(int i=1;i<=n;i++){ int x=s[i]-'a',now=get_fail(last,i); if(!son[now][x]){ new_node(len[now]+2); fail[cnt]=son[get_fail(fail[now],i)][x]; son[now][x]=cnt; } last=son[now][x]; ans[last]++; }}int main(){ scanf("%s",s+1); n=strlen(s+1); cnt--; new_node(0),new_node(-1); fail[1]=fail[0]=1; last=0; build(); for(int i=cnt;i>=0;i--)ans[fail[i]]+=ans[i]; for(int i=0;i<=cnt;i++)Ans=max(Ans,(long long)len[i]*ans[i]); cout<

转载于:https://www.cnblogs.com/yzxverygood/p/10386825.html

你可能感兴趣的文章
计数排序
查看>>
nginx 和 php超时设置
查看>>
[复变函数]第03堂课 1.2 复平面上的点集
查看>>
Servlet学习之web服务器Tomcat 详解
查看>>
Python:Opening Python Classes
查看>>
mvc:view-controller
查看>>
Android推送分析
查看>>
HDU 3336 Count the string 查找匹配字符串
查看>>
ExpandoObject对象的JSON序列化
查看>>
微信公众平台开发者文档
查看>>
c# 反射取其他项目的资源文件
查看>>
Oleg Sych - » Pros and Cons of T4 in Visual Studio 2008
查看>>
在一个未知的CentOS服务器中如何加上PHP的openssl扩展
查看>>
高性能网站构建实战文摘
查看>>
数学图形(1.4)心形线
查看>>
调试WebService
查看>>
学习的方法
查看>>
Atitit. 提升开发效率与质量DSL ( 3) ----实现DSL的方式总结
查看>>
手机SD卡损坏补救措施
查看>>
ORACLE数据库不同故障下的恢复总结
查看>>