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

另一种更简单更快常数更小的写法,很神奇……背板子。

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
using namespace std;
const int maxn=;
char ch[maxn];
int siz;
struct pam{
int sig[];
int f,len,cnt;
}t[maxn];
int tot=,las=;
long long ans=;
void add(int z,int n){
int p=las;
while(ch[n-t[p].len-]!=ch[n])p=t[p].f;
if(!t[p].sig[z]){
int y=++tot;int k=t[p].f;
t[y].len=t[p].len+;
while(ch[n-t[k].len-]!=ch[n])k=t[k].f;
t[y].f=t[k].sig[z];t[p].sig[z]=y;//注意这里的顺序是不能调整的
}
las=t[p].sig[z];
t[las].cnt++;
}
void solve(){
for(int i=tot;i;i--){
t[t[i].f].cnt+=t[i].cnt;
ans=max(ans,(long long )t[i].cnt*t[i].len);
}
}
int main(){
memset(t,,sizeof(t));t[].f=t[].f=;t[].len=-;
scanf("%s",ch+);siz=strlen(ch+);
for(int i=;i<=siz;i++)add(ch[i]-'a',i);
solve();
printf("%lld\n",ans);
return ;
}

BZOJ 3676: [Apio2014]回文串 回文树 回文自动机的更多相关文章

  1. 力扣算法:125-验证回文串,131-分割回文串---js

    LC 125-验证回文串 给定一个字符串,验证它是否是回文串,只考虑字母和数字字符,可以忽略字母的大小写. 说明:本题中,我们将空字符串定义为有效的回文串. 注:回文串是正着读和反着读都一样的字符串. ...

  2. BZOJ 3676: [Apio2014]回文串

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

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

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

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

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

  5. ●BZOJ 3676 [Apio2014]回文串

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

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

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

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

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

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

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

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

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

  10. 洛谷P4555 [国家集训队]最长双回文串(manacher 线段树)

    题意 题目链接 Sol 我的做法比较naive..首先manacher预处理出以每个位置为中心的回文串的长度.然后枚举一个中间位置,现在要考虑的就是能覆盖到i - 1的回文串中 中心最靠左的,和能覆盖 ...

随机推荐

  1. G6踩坑日记

    用G6去完成一整个图例的时候,当包裹它的容器满足不了包裹的需求时,我们就需要引入缩略图来解决问题了 缩略图使用方式很简单 引入插件配置就可以了 当我们使用多张图片进行绘图(G6支持使用图片进行构图,原 ...

  2. C#里面中将字符串转为变量名

    public partial class Form1 : Form { string str = "spp"; public string spp = "very goo ...

  3. tf.reduce_sum()_tf.reduce_mean()_tf.reduce_max()

    根据官方文档: reduce_sum应该理解为压缩求和,用于降维 tf.reduce_sum(input_tensor,axis=None,keepdims=None,name=None,reduct ...

  4. PHP 不让标准浏览器(firfox,chrome等)走浏览器的缓存页面

    或在HTML页面里加: <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache,no-store, must-reva ...

  5. 集合框架之Map学习

    Map接口的实现类有HashTable.HashMap.TreeMap等,文章学习整理了“ Map和HashMap的使用方法”. /** * Map和HashMap的使用方法 */public sta ...

  6. tftp 开发板ping不通PC机

    开发板:JZ2440(天下2440开发板是一家) 当进入uboot界面时:输入命令print则显示: 将PC端的IP设置为192.168.1.11 在开发板上ping   192.168.1.11,若 ...

  7. Oracle常用sql语句(三)之子查询

    子查询 子查询要解决的问题,不能一步求解 分为: 单行子查询 多行子查询 语法: SELECT select_list FROM table WHERE expr operator (SELECT s ...

  8. leetcode Two Sum II - Input array is sorted <面试常考题>

    题目描述 //二分查找的变形   用头尾两个指针进行  面试考察题 class Solution { public: vector<int> twoSum(vector<int> ...

  9. mysql root 密码恢复

    1.停止mysql服务 service mysql stop 2.启动mysql时不启动授权表,跳过权限验证使用空密码登陆 mysqld_safe --skip-grant-tables & ...

  10. hive学习(五) 应用案例

    1.实现struct数据结构例子 1.1创建student表 create table student( id int, info struct<name:string,age:int> ...