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;
}

  

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

【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]回文串(回文树)

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

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

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

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

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

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

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

  9. BZOJ.3676.[APIO2014]回文串(回文树)

    BZOJ 洛谷 很久之前写(抄)过一个Hash+Manacher的做法,当时十分懵逼=-= 然而是道回文树模板题. 回文树教程可以看这里(真的挺妙的). 顺便再放上MilkyWay的笔记~ //351 ...

  10. bzoj 3676: [Apio2014]回文串【后缀自动机+manacher】

    用manacher找出本质不同的回文子串放在SAM上跑 #include<iostream> #include<cstdio> #include<cstring> ...

随机推荐

  1. ASP.NET Web API 控制请求频率

    参考地址:http://www.cnblogs.com/shanyou/p/3194802.html 安装nuget包:WebApiContrib 很多的api,例如GitHub’s API 都有流量 ...

  2. 【PHP自定义显示系统级别的致命错误和用户级别的错误】

    使用方法set_error_handler可以自定义用户级别的错误和系统级别的错误信息显示和处理 用户级别的错误使用trigger_error方法产生一个用户级别的错误信息 代码示例: 系统级别的错误 ...

  3. 【叉积】【sdut 2508 图形密码】

    图形密码 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 题目链接:http://acm.sdut.edu.cn/sdutoj/p ...

  4. 无废话ExtJs 入门教程六[按钮:Button]

    无废话ExtJs 入门教程六[按钮:Button] extjs技术交流,欢迎加群(201926085) 继上一节内容,我们在表单里加了个两个按钮“提交”与重置.如下所示代码区的第68行位置, butt ...

  5. hdu 3695:Computer Virus on Planet Pandora(AC自动机,入门题)

    Computer Virus on Planet Pandora Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 256000/1280 ...

  6. android 入门-Activity及 字体

    private Button sButton; private TextView mTextView; private Button fButton; ,,,,}; @Override protect ...

  7. RTP 与RTCP 解释. 含同步时间戳

    转自:http://blog.csdn.net/wudebao5220150/article/details/13816225 RTP协议是real-time transport protocol的缩 ...

  8. 强化的单例属性_Effective Java

    Singleton指的是仅仅被实例化一次的类,比如唯一的系统组件等,成为Singleton的类测试起来也比较困难. 常用的方法: 1.公有静态final域+私有构造器 public class Egg ...

  9. MySQL主从复制(Master-Slave)与读写分离(MySQL-Proxy)实践

    主服务器上(注:应该是允许从机访问)  GRANT REPLICATION SLAVE ON *.* to ‘rep1’@’192.168.10.131’ identified by ‘passwor ...

  10. Ubuntu中如何打开终端terminal

    法一 先按住Alt,然后再按F2,出来一个运行框,在里面输入gnome-terminal即可 [编辑]法二 如果想从右键菜单中打开终端,需要安装一个软件: sudoapt-get install na ...