BZOJ 3676: [Apio2014]回文串 回文树 回文自动机
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]回文串 回文树 回文自动机的更多相关文章
- 力扣算法:125-验证回文串,131-分割回文串---js
LC 125-验证回文串 给定一个字符串,验证它是否是回文串,只考虑字母和数字字符,可以忽略字母的大小写. 说明:本题中,我们将空字符串定义为有效的回文串. 注:回文串是正着读和反着读都一样的字符串. ...
- BZOJ 3676: [Apio2014]回文串
3676: [Apio2014]回文串 Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 2013 Solved: 863[Submit][Status ...
- bzoj 3676: [Apio2014]回文串 回文自动机
3676: [Apio2014]回文串 Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 844 Solved: 331[Submit][Status] ...
- 字符串(马拉车算法,后缀数组,稀疏表):BZOJ 3676 [Apio2014]回文串
Description 考虑一个只包含小写拉丁字母的字符串s.我们定义s的一个子串t的“出 现值”为t在s中的出现次数乘以t的长度.请你求出s的所有回文子串中的最 大出现值. Input 输入只有一行 ...
- ●BZOJ 3676 [Apio2014]回文串
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=3676 题解: 后缀数组,Manacher,二分 首先有一个结论:一个串的本质不同的回文串的个 ...
- bzoj 3676 [Apio2014]回文串(Manacher+SAM)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3676 [题意] 给定一个字符串,定义一个串的权值为长度*出现次数,求最大权的回文子串. ...
- BZOJ 3676 [Apio2014]回文串(回文树)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3676 [题目大意] 考虑一个只包含小写拉丁字母的字符串s. 我们定义s的一个子串t的& ...
- bzoj 3676: [Apio2014]回文串【回文自动机】
回文自动机板子 或者是SAM+manacher+倍增,就是manacher求本质不同回文串(让f++的串),然后在SAM倍增查询对应点出现次数 #include<iostream> #in ...
- BZOJ 3676 [Apio2014]回文串 (后缀自动机+manacher/回文自动机)
题目大意: 给你一个字符串,求其中回文子串的长度*出现次数的最大值 明明是PAM裸题我干嘛要用SAM做 回文子串有一个神奇的性质,一个字符串本质不同的回文子串个数是$O(n)$级别的 用$manach ...
- 洛谷P4555 [国家集训队]最长双回文串(manacher 线段树)
题意 题目链接 Sol 我的做法比较naive..首先manacher预处理出以每个位置为中心的回文串的长度.然后枚举一个中间位置,现在要考虑的就是能覆盖到i - 1的回文串中 中心最靠左的,和能覆盖 ...
随机推荐
- 【不能继续浪啦】BZ做题记录[7.01~7.06]
距离上次提交..><居然已经过去一个半月了... 然后再去看看人家RXDoi.. 差距越来越大啦... 最后更新时间:7.06 19:06 [07.03 21:02]夏令营自修课逃逃真爽. ...
- Global.asax文件—ASP.NET细枝末节(1)
说明 Global的解释是全局的.全球的. Global.asax 文件,有时候叫做 ASP.NET 应用程序文件,提供了一种在一个中心位置响应应用程序级或模块级事件的方法.你可以使用这个文件实现应用 ...
- iOS网络基础---iOS-Apple苹果官方文档翻译
CHENYILONG Blog iOS网络基础---iOS-Apple苹果官方文档翻译 iOS网络基础 技术博客http://www.cnblogs.com/ChenYilong/ 新浪微博http: ...
- 2017ACM暑期多校联合训练 - Team 4 1003 HDU 6069 Counting Divisors (区间素数筛选+因子数)
题目链接 Problem Description In mathematics, the function d(n) denotes the number of divisors of positiv ...
- NYOJ 221 Tree (二叉树)
题目链接 描述 Little Valentine liked playing with binary trees very much. Her favorite game was constructi ...
- Flask 的一个小应用程序
传说这是Flask 的最小应用程序:hello.py from flask import Flask app = Flask(__name__) @app.route('/') def hello_w ...
- Double类型的数向上取整和向下取整
- URAL题解一
URAL题解一 URAL 1002 题目描述:一种记住手机号的方法就是将字母与数字对应,如图.这样就可以只记住一些单词,而不用记住数字.给出一个数字串和n个单词,用最少的单词数来代替数字串,输出对应的 ...
- 报错:/application/zabbix/sbin/zabbix_server: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
启动zabbix_server时报错: /application/zabbix/sbin/zabbix_server: error while loading shared libraries: li ...
- php直接输出json格式
php直接输出json格式,很多新手有一个误区,以为用echo json_encode($data);这样就是输出json数据了,没错这样输出文本是json格式文本而不是json数据,正确的写法是应该 ...