Bryce1010模板

http://www.tsinsen.com/A1280###

题目分析:记录一个点向后和向前的最长回文串,然后就是max(Llen[i]+Rlen[i+1])了。

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std ;
typedef long long LL ;
#define rep( i , a , b ) for ( int i = ( a ) ; i < ( b ) ; ++ i )
#define For( i , a , b ) for ( int i = ( a ) ; i <= ( b ) ; ++ i )
#define rev( i , a , b ) for ( int i = ( a ) ; i >= ( b ) ; -- i )
#define clr( a , x ) memset ( a , x , sizeof a )
const int MAXN = 100005 ;
const int N = 26 ; struct Palindromic_Tree {
int next[MAXN][N] ;
int fail[MAXN] ;
int cnt[MAXN] ;
int len[MAXN] ;
int S[MAXN] ;
int last ;
int n ;
int p ; int newnode ( int l ) {
for ( int i = 0 ; i < N ; ++ i ) next[p][i] = 0 ;
cnt[p] = 0 ;
len[p] = l ;
return p ++ ;
} void init () {
p = 0 ;
newnode ( 0 ) ;
newnode ( -1 ) ;
last = 0 ;
n = 0 ;
S[n] = -1 ;
fail[0] = 1 ;
} int get_fail ( int x ) {
while ( S[n - len[x] - 1] != S[n] ) x = fail[x] ;
return x ;
} int add ( int c ) {
c -= 'a' ;
S[++ n] = c ;
int cur = get_fail ( last ) ;
if ( !next[cur][c] ) {
int now = newnode ( len[cur] + 2 ) ;
fail[now] = next[get_fail ( fail[cur] )][c] ;
next[cur][c] = now ;
}
last = next[cur][c] ;
cnt[last] ++ ;
return len[last] ;
} void count () {
for ( int i = p - 1 ; i >= 0 ; -- i ) cnt[fail[i]] += cnt[i] ;
}
} ; Palindromic_Tree T ;
int n ;
int len[MAXN] ;
char s[MAXN] ; void solve () {
int ans = 0 ;
n = strlen ( s ) ;
T.init () ;
for ( int i = n - 1 ; i >= 0 ; -- i ) {
len[i] = T.add ( s[i] ) ;
}
T.init () ;
for ( int i = 0 ; i < n - 1 ; ++ i ) {
ans = max ( ans , T.add ( s[i] ) + len[i + 1] ) ;
}
printf ( "%d\n" , ans ) ;
} int main () {
while ( ~scanf ( "%s" , s ) ) solve () ;
return 0 ;
}

【Tsinsen】A1280. 最长双回文串的更多相关文章

  1. 青橙 A1280. 最长双回文串

    A1280. 最长双回文串 时间限制:2.0s   内存限制:512.0MB   总提交次数:   AC次数:   平均分:   将本题分享到:        查看未格式化的试题   提交   试题讨 ...

  2. A1280. 最长双回文串

    学习了回文树,地址:http://blog.csdn.net/u013368721/article/details/42100363: 这个题就是正这反着加一遍就好,一开始我想的是枚举每个位置,然后一 ...

  3. Tsinsen 最长双回文串

    求最长双回文串,正反建回文树求最大. 题目链接:http://www.tsinsen.com/ViewGProblem.page?gpid=A1280 By:大奕哥 #include<bits/ ...

  4. BZOJ 2565: 最长双回文串 [Manacher]

    2565: 最长双回文串 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1842  Solved: 935[Submit][Status][Discu ...

  5. 【BZOJ2565】最长双回文串(回文树)

    [BZOJ2565]最长双回文串(回文树) 题面 BZOJ 题解 枚举断点\(i\) 显然的,我们要求的就是以\(i\)结尾的最长回文后缀的长度 再加上以\(i+1\)开头的最长回文前缀的长度 至于最 ...

  6. BZOJ.2565.[国家集训队]最长双回文串(Manacher/回文树)

    BZOJ 洛谷 求给定串的最长双回文串. \(n\leq10^5\). Manacher: 记\(R_i\)表示以\(i\)位置为结尾的最长回文串长度,\(L_i\)表示以\(i\)开头的最长回文串长 ...

  7. P4555 [国家集训队]最长双回文串

    P4555 [国家集训队]最长双回文串 manacher 用manacher在处理时顺便把以某点开头/结尾的最长回文串的长度也处理掉. 然后枚举. #include<iostream> # ...

  8. bzoj 2565: 最长双回文串 manacher算法

    2565: 最长双回文串 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/problem. ...

  9. 【BZOJ2565】最长双回文串 Manacher

    [BZOJ2565]最长双回文串 Description 顺序和逆序读起来完全一样的串叫做回文串.比如acbca是回文串,而abc不是(abc的顺序为“abc”,逆序为“cba”,不相同).输入长度为 ...

随机推荐

  1. Arcgis Engine(ae)接口详解(1):featureClass

    //IFeatureClass 来源请自行解决 IFeatureClass featureClass = null; //获取featureClass的各种名称 //PS:featureClass可以 ...

  2. 李雅普诺夫函数 LyapunovFunction 李雅普诺夫意义下的稳定性

    https://zh.wikipedia.org/zh-hans/李亞普諾夫函數 李雅普诺夫函数(Lyapunov function)是用来证明一动力系统或自治微分方程稳定性的函数.其名称来自俄罗斯数 ...

  3. gcc 头文件是用户应用程序和函数库之间的桥梁和纽带 功能的真正逻辑实现是以硬件层为基础

    gcc GCC, the GNU Compiler Collection - GNU Project - Free Software Foundation (FSF) http://gcc.gnu.o ...

  4. CSS3 的10种Loading

    昨晚用CSS3实现了几种常见的Loading效果,虽然很简单,但还是分享一下,顺便也当是做做笔记…… 第1种效果: 代码如下: <div class="loading"> ...

  5. kafka 和 zookeeper 常用命令记录

    启动zookeeper zkServer.sh start 启动kafka服务器 kafka-server-start.sh /software/kafka_2.10-0.10.2.1/config/ ...

  6. react native 之页面跳转

    第一章  跳转的实现 1.component  中添加这行代码 <View style={styles.loginmain}> <Text style={styles.loginte ...

  7. ZOJ3469 Food Delivery —— 区间DP

    题目链接:https://vjudge.net/problem/ZOJ-3469 Food Delivery Time Limit: 2 Seconds      Memory Limit: 6553 ...

  8. 理解 Android MVP 开发模式

    /***************************************************************************************** * 理解 Andr ...

  9. MDZX——张能传

    「你们到底要干什么?!」——8012年7月13日 张能于MDZX ———————————— 序章 ———————————— 话说天下大势,分久必合,合久必分. 他肩扛99米大砍刀,站在MDZX大门对面 ...

  10. 数据库sql互转(oracle转mysql为例子)

    转自: https://blog.csdn.net/sinat_32366329/article/details/76402059 在PowerDesinger里找到 File -->> ...