UOJ#103. 【APIO2014】Palindromes PAM模板题
原文链接www.cnblogs.com/zhouzhendong/p/UOJ103.html
前言
我终于会PAM啦
感谢CLY大佬手把手教我PAM
题解
建个 PAM。
统计一下每一个节点的 Right 集合大小,设 size[x] 为节点 x 的 right 集合大小。
求出 max(len[x] * size[x]) ,做完了。
代码
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof (x))
#define For(i,a,b) for (int i=a;i<=b;i++)
#define Fod(i,b,a) for (int i=b;i>=a;i--)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define _SEED_ ('C'+'L'+'Y'+'A'+'K'+'I'+'O'+'I')
#define outval(x) printf(#x" = %d\n",x)
#define outvec(x) printf("vec "#x" = ");for (auto _v : x)printf("%d ",_v);puts("")
#define outtag(x) puts("----------"#x"----------")
#define outarr(a,L,R) printf(#a"[%d...%d] = ",L,R);\
For(_v2,L,R)printf("%d ",a[_v2]);puts("");
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector <int> vi;
LL read(){
LL x=0,f=0;
char ch=getchar();
while (!isdigit(ch))
f|=ch=='-',ch=getchar();
while (isdigit(ch))
x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
return f?-x:x;
}
const int N=300005;
int n;
char s[N];
namespace PAM{
int len[N],Fail[N],Next[N][26];
int size[N];
int cnt;
void init(){
cnt=2;
len[1]=-1,Fail[1]=1;
len[2]=0,Fail[2]=1;
clr(Next),clr(size);
}
void build(char *s,int n){
init();
s[0]='*';
int x=1;
For(i,1,n){
while (s[i-len[x]-1]!=s[i])
x=Fail[x];
int c=s[i]-'a';
if (Next[x][c])
x=Next[x][c];
else {
int y=Next[x][c]=++cnt;
len[y]=len[x]+2;
if (len[y]==1)
Fail[y]=2;
else {
x=Fail[x];
while (s[i-len[x]-1]!=s[i])
x=Fail[x];
Fail[y]=Next[x][c];
}
x=y;
}
size[x]++;
}
Fod(i,cnt,1)
size[Fail[i]]+=size[i];
}
LL solve(){
LL ans=0;
For(i,2,cnt)
ans=max(ans,(LL)len[i]*size[i]);
return ans;
}
}
int main(){
scanf("%s",s+1);
n=strlen(s+1);
PAM::build(s,n);
cout<<PAM::solve()<<endl;
return 0;
}
UOJ#103. 【APIO2014】Palindromes PAM模板题的更多相关文章
- UOJ #146. 【NOIP2015】信息传递 连通分量 tarjan模板题
http://uoj.ac/problem/146 题解:强连通分量 tarjan模板题.同时试了一下codeblock #include<bits/stdc++.h> using nam ...
- Bellman-Ford算法模板题
POJ 3259 虫洞(Bellman-Ford判断有无负环的问题) 描述: 在探索他的许多农场时,Farmer John发现了许多令人惊叹的虫洞.虫洞是非常奇特的,因为它是一条单向路径,在您进入虫洞 ...
- 离散化模板题 I ——重复元素离散化后的数字相同
离散化模板题 I --重复元素离散化后的数字相同 题目描述 现有数列A1, A2, ⋯, An,数列中可能有重复元素. 现在要求输出该数列的离散化数列,重复元素离散化后的数字相同. 输入 第一行,一 ...
- [AHOI 2009] 维护序列(线段树模板题)
1798: [Ahoi2009]Seq 维护序列seq Time Limit: 30 Sec Memory Limit: 64 MB Description 老师交给小可可一个维护数列的任务,现在小 ...
- HDU 2222 AC自动机模板题
题目: http://acm.hdu.edu.cn/showproblem.php?pid=2222 AC自动机模板题 我现在对AC自动机的理解还一般,就贴一下我参考学习的两篇博客的链接: http: ...
- POJ2774 & 后缀数组模板题
题意: 求两个字符串的LCP SOL: 模板题.连一起搞一搞就好了...主要是记录一下做(sha)题(bi)过程心(cao)得(dan)体(xin)会(qing) 后缀数组概念...还算是简单的,过程 ...
- HDU 1251 Trie树模板题
1.HDU 1251 统计难题 Trie树模板题,或者map 2.总结:用C++过了,G++就爆内存.. 题意:查找给定前缀的单词数量. #include<iostream> #incl ...
- HDU-3549 最大流模板题
1.HDU-3549 Flow Problem 2.链接:http://acm.hdu.edu.cn/showproblem.php?pid=3549 3.总结:模板题,参考了 http://ww ...
- HDU 4280:Island Transport(ISAP模板题)
http://acm.hdu.edu.cn/showproblem.php?pid=4280 题意:在最西边的点走到最东边的点最大容量. 思路:ISAP模板题,Dinic过不了. #include & ...
随机推荐
- Linux,Ubuntu,Mint 环境下 navicat 乱码问题
1. 官方下载好以后,进入目录 执行 ./start_navicat 可以启动软件. 2. 如果有乱码,首先,使用编辑器打开 start_navicat ,比如 vim start_navicat ...
- 【持续跟新】剑指Offer_Java实现
[第一题 ]二维数组中的查找 package sword_finger_offer; import org.junit.jupiter.api.Test; /** * 剑指offer习题一 二维数组中 ...
- Java IO系列之二:NIO基本操作
核心部分 NIO( New Input/ Output) , 引入了一种基于通道和缓冲区的 I/O 方式,NIO 是一种同步非阻塞的 IO 模型.同步是指线程不断轮询 IO 事件是否就绪,非阻塞是指 ...
- 阿里云OSS的Bucket容量大小采集
#!/usr/bin/env python3 #-*- coding: utf-8 -*- # 获取阿里云云监控中 OSS 中的bucket 的bucket大小 from aliyunsdkcore. ...
- uCos-II中任务的同步与通信
任务的同步与通信 任务间的同步 在多任务合作工作过程中,操作系统要解决两个问题: 各任务间应该具有一种互斥关系,即对某些共享资源,如果一个任务正在使用,则其他任务只能等待,等到该任务释放资源后,等待任 ...
- react native navigationOptions中不能获取this
static navigationOptions = ({ navigation, navigationOptions,screenProps }) => { const { params } ...
- iTOP-iMX6UL开发板【全能版】-动态调频技术简介
本文档以 iMX6UL 为例,简单介绍 cpufreq 的 5 种模式. 在 imx6ul 的 menuconfig 中,进入 CPU Power Management ---> CPU Fre ...
- vue keep-alive内置缓存组件
1.当组件在keep-alive被切换时将会执行activeted和deactiveted两个生命周期 2.inlude 正则表达式或字符串 ,只有符合条件的组件会被缓存 exclude正则表达式或字 ...
- my.ini的路径分隔符
又踩了个坑,今天安装mysql,路径为F:\test\mysql于是我配置my.ini如下 [mysqld] basedir=F:\test\mysql datadir=F:\test\mysql\d ...
- 论文阅读笔记(二)U-Net
U-Net: Convolutional Networks for Biomedical Image Segmentation U-Net:用于生物医学图像分割的卷积网络 摘要 要想成功地训练一个深度 ...