【题目链接】 http://www.lydsy.com/JudgeOnline/problem.php?id=3676

【题目大意】

  考虑一个只包含小写拉丁字母的字符串s。
  我们定义s的一个子串t的"出现值"为t在s中的出现次数乘以t的长度。
  求s的所有回文子串中的最大出现值。

【题解】

  我们对给出串建立回文树,统计每个回文串出现次数和长度,相乘取组大即可

【代码】

#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int N=300010,S=26;
int all,son[N][S],fail[N],cnt[N],len[N],text[N],last,tot;
int newnode(int l){
for(int i=0;i<S;i++)son[tot][i]=0;
cnt[tot]=0,len[tot]=l;
return tot++;
}
void init(){
last=tot=all=0;
newnode(0),newnode(-1);
text[0]=-1,fail[0]=1;
}
int getfail(int x){
while(text[all-len[x]-1]!=text[all])x=fail[x];
return x;
}
void add(int w){
text[++all]=w;
int x=getfail(last);
if(!son[x][w]){
int y=newnode(len[x]+2);
fail[y]=son[getfail(fail[x])][w];
son[x][w]=y;
}cnt[last=son[x][w]]++;
}
void count(){for(int i=tot-1;~i;i--)cnt[fail[i]]+=cnt[i];}
char s[N];
int main(){
while(~scanf("%s",s)){
int n=strlen(s);
init();
for(int i=0;i<n;i++)add(s[i]-'a');
count(); long long ans=0;
for(int i=0;i<tot;i++)ans=max(ans,1LL*cnt[i]*len[i]);
printf("%lld\n",ans);
}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]回文串【回文自动机】

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

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

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

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

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

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

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

随机推荐

  1. B. Complete the Word(Codeforces Round #372 (Div. 2)) 尺取大法

    B. Complete the Word time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  2. H题 hdu 2520 我是菜鸟,我怕谁

    题目大意:http://acm.hdu.edu.cn/showproblem.php?pid=2520 我是菜鸟,我怕谁 Time Limit: 2000/1000 MS (Java/Others)  ...

  3. Ribbon/Feign/Zuul retry

    原文 https://github.com/spring-cloud/spring-cloud-netflix/issues/1577 I'm using Spring Cloud Camden SR ...

  4. Python阶段复习 - part 4 - 用户登录程序

    简易版: #!/usr/bin/env python # _*_ coding:UTF-8 _*_ # __auth__:Dahlhin import sys userinfo = r'userinf ...

  5. 【EverydaySport】健身笔记——背部训练

    背部训练大致可以分为两种. 1 下拉式动作 躯干纵向上下位移的动作 典型代表 这样的下拉类动作 针对的是背阔肌 也就是两边像翅膀一样的部分 2 垂直于躯干的方向作用 向内拉 主要针对的是,背部的中部 ...

  6. 在linux下有没有什么软件可以连接windows上的MSSQL SERVER

    在linux下有没有什么软件可以连接windows上的MSSQL SERVER GUI的http://dbeaver.jkiss.org/ http://bbs.csdn.net/topics/391 ...

  7. C#数据没初始化,使用会报错,可以初始化null

    protected void Page_Load(object sender, EventArgs e) { string[] A; if (B== 0) { A = new string[] {1, ...

  8. C++ STL结构总结

    1. 什么是STL 它的全名是stand template library, 标准模板库,主要是将一些结构和算法写成模板,以便能够实现对任意类型的对象都可以操作,而不需要再一次去写一些算法及结构. 它 ...

  9. awk处理之案例六:awk根据条件插入文本

    编译环境 本系列文章所提供的算法均在以下环境下编译通过. [脚本编译环境]Federa 8,linux 2.6.35.6-45.fc14.i686 [处理器] Intel(R) Core(TM)2 Q ...

  10. Integer to Roman——相当于查表法

    Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...