BZOJ

洛谷

很久之前写(抄)过一个Hash+Manacher的做法,当时十分懵逼=-=

然而是道回文树模板题。

回文树教程可以看这里(真的挺妙的)。

顺便再放上MilkyWay的笔记~

//35100kb	708ms
#include <cstdio>
#include <cstring>
#include <algorithm>
#define gc() getchar()
typedef long long LL;
const int N=3e5+5; struct Palindromic_Tree
{
int las,tot,son[N][26],len[N],fail[N],val[N];
char s[N]; Palindromic_Tree() {tot=1, fail[0]=1, len[1]=-1, s[0]='$';}
inline int Find(int x,int n)
{
while(s[n-len[x]-1]!=s[n]) x=fail[x];
return x;
}
void Insert(int c,int n)
{
int p=Find(las,n);
if(!son[p][c])
{
int np=++tot; fail[np]=son[Find(fail[p],n)][c];
son[p][c]=np, len[np]=len[p]+2;
}
++val[las=son[p][c]];
}
void Solve()
{
scanf("%s",s+1); int n=strlen(s+1);
for(int i=1; i<=n; ++i) Insert(s[i]-'a',i);
LL ans=0;
for(int i=tot; i>1; --i)
val[fail[i]]+=val[i], ans=std::max(ans,1ll*val[i]*len[i]);
printf("%lld\n",ans);
}
}T; int main()
{
T.Solve();
return 0;
}

BZOJ.3676.[APIO2014]回文串(回文树)的更多相关文章

  1. BZOJ 3676: [Apio2014]回文串

    3676: [Apio2014]回文串 Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 2013  Solved: 863[Submit][Status ...

  2. bzoj 3676: [Apio2014]回文串 回文自动机

    3676: [Apio2014]回文串 Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 844  Solved: 331[Submit][Status] ...

  3. 字符串(马拉车算法,后缀数组,稀疏表):BZOJ 3676 [Apio2014]回文串

    Description 考虑一个只包含小写拉丁字母的字符串s.我们定义s的一个子串t的“出 现值”为t在s中的出现次数乘以t的长度.请你求出s的所有回文子串中的最 大出现值. Input 输入只有一行 ...

  4. ●BZOJ 3676 [Apio2014]回文串

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=3676 题解: 后缀数组,Manacher,二分 首先有一个结论:一个串的本质不同的回文串的个 ...

  5. bzoj 3676 [Apio2014]回文串(Manacher+SAM)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3676 [题意] 给定一个字符串,定义一个串的权值为长度*出现次数,求最大权的回文子串. ...

  6. BZOJ 3676 [Apio2014]回文串(回文树)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3676 [题目大意] 考虑一个只包含小写拉丁字母的字符串s. 我们定义s的一个子串t的& ...

  7. bzoj 3676: [Apio2014]回文串【回文自动机】

    回文自动机板子 或者是SAM+manacher+倍增,就是manacher求本质不同回文串(让f++的串),然后在SAM倍增查询对应点出现次数 #include<iostream> #in ...

  8. BZOJ 3676 [Apio2014]回文串 (后缀自动机+manacher/回文自动机)

    题目大意: 给你一个字符串,求其中回文子串的长度*出现次数的最大值 明明是PAM裸题我干嘛要用SAM做 回文子串有一个神奇的性质,一个字符串本质不同的回文子串个数是$O(n)$级别的 用$manach ...

  9. HYSBZ 3676 回文串 (回文树)

    3676: [Apio2014]回文串 Time Limit: 20 Sec  Memory Limit: 128 MB Submit: 1680  Solved: 707 [Submit][Stat ...

  10. 【bzoj3676】[Apio2014]回文串 —— 回文自动机的学习

    写题遇上一棘手的题,[Apio2014]回文串,一眼看过后缀数组+Manacher.然后就码码码...过是过了,然后看一下[Status],怎么慢这么多,不服..然后就搜了一下,发现一种新东西——回文 ...

随机推荐

  1. WPA2-PSK无线密码破解

    无线网络WIFI(wireless Fidelity )正确发音 /wai fai/ 是一个建立在IEEE 802.11标准的无线局域网,目前主流的无线上网模式主要有两种分别是 GRPS(手机无线上网 ...

  2. Pycharm同步本地代码至GitHub

    注册github账号 github地址,进入注册账号 安装git Windows下载地址1 Windows下载地址2 在官方下载完后,双击exe文件进行安装,安装到Windows Explorer i ...

  3. SSM 三大框架---事务处理

    SSM 三大框架---事务处理 原创 2016年05月12日 20:57:03 标签: spring / J2EE / java / 框架 / 事务 7010 在学习三大框架的时候,老师说事务处理是最 ...

  4. shell 排除目录

    1.新建文件 exclude.txt,在文件中写需要排除的目录(只需要目录名称,不需要路径) 2.--exclude-from='/data/www/vhosts/git_track/git-shel ...

  5. XMind思维导图使用笔记

    首先新建一个空白的图 以组织结构图(向下)  为例 1.双击组织结构图 创建一个空白的页面 2.随便选择一个风格 这时候出现工作台 现在里面只有一个中心主题 正文部分开始 1.如果想要添加一个子主题 ...

  6. Eclipes导入工程

    1.在eclipes中导入其他的一些工程后往往会出错,修改意见是 在project.properties该文件下修改 这个target是你的sdk中已经下载好的 查看: 右键目标工程,选择proper ...

  7. vs问题解决:an operation is not legal in the current state

    debug时弹出提示框:内容有:an operation is not legal in the current state 解决方案: Go to Tools > Options > D ...

  8. C#通讯录——Windows Form Contact List

    C#通讯录 Windows Form Contact List 主窗口 using System; using System.Collections.Generic; using System.Com ...

  9. How to trigger an Animation when TextBlock’s Text is changed during a DataBinding

    原文:http://michaelscherf.wordpress.com/2009/02/23/how-to-trigger-an-animation-when-textblocks-text-is ...

  10. json2csharp & json 格式化

    json2csharp: http://json2csharp.com/ bejson: http://www.bejson.com/