经典题

manacher是一种很神奇的算法,

算是动态规划的一种,不过利用的信息非常有效

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn = 1e5 + ;
char S2[maxn*], str[maxn*];
int R[maxn*];
void Manacher(char* S){
int L = strlen(S);
for(int i = , j = ; i < *L; i += , j += ) S2[i] = '#', S2[j] = S[j/];
S2[*L] = '#';
int mx = -, id = -;
for(int i = ; i < *L; i++){
R[i] = mx-i >= ? min(R[*id-i], mx-i+) : ;
while(i+R[i] <= *L && S2[i+R[i]] == S2[i-R[i]]) R[i]++;
if(i+R[i]- > mx) mx = i+R[i]-, id = i;
}
} int main()
{
cin>>str;
Manacher(str);
int L = strlen(str), ans = ;
//for(int i = 0; i < 2*L; i++) cout<<R[i]<<" "; cout<<endl;
for(int i = ; i < *L; i += ) ans = max(ans, *(R[i]/-) + );
for(int i = ; i < *L; i += ) ans = max(ans, R[i]-);
cout<<ans<<endl;
return ;
}

51nod 1089最长回文子串V2 (manacher)的更多相关文章

  1. 51Nod 1089 最长回文子串 V2 —— Manacher算法

    题目链接:https://vjudge.net/problem/51Nod-1089 1089 最长回文子串 V2(Manacher算法) 基准时间限制:1 秒 空间限制:131072 KB 分值:  ...

  2. 51nod(1089 最长回文子串 V2)(hash 加二分)

    1089 最长回文子串 V2(Manacher算法)   回文串是指aba.abba.cccbccc.aaaa这种左右对称的字符串. 输入一个字符串Str,输出Str里最长回文子串的长度.   输入 ...

  3. 51nod 1089 最长回文子串 V2(Manacher算法)

    回文串是指aba.abba.cccbccc.aaaa这种左右对称的字符串. 输入一个字符串Str,输出Str里最长回文子串的长度. 收起   输入 输入Str(Str的长度 <= 100000) ...

  4. 51nod 1089 最长回文子串 V2(Manacher算法)

    基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 输入N求N的阶乘的10进制表示的长度.例如6! = 720,长度为3.   Input 第1行:一个数T,表示后面用作输入 ...

  5. 51NOD 1088 最长回文子串&1089 最长回文子串 V2(Manacher算法)

    回文串是指aba.abba.cccbccc.aaaa这种左右对称的字符串. 输入一个字符串Str,输出Str里最长回文子串的长度. Input 输入Str(Str的长度 <= 1000(第二题要 ...

  6. 1089 最长回文子串 V2(Manacher算法)

    1089 最长回文子串 V2(Manacher算法) 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 回文串是指aba.abba.cccbccc.aaaa ...

  7. 51 Nod 1089 最长回文子串(Manacher算法)

    1089 最长回文子串 V2(Manacher算法)  基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 回文串是指aba.abba.cccbccc.aaa ...

  8. 【51NOD-0】1089 最长回文子串 V2(Manacher算法)

    [算法]回文树 #include<cstdio> #include<algorithm> #include<cstring> using namespace std ...

  9. 51Nod 1089:最长回文子串 V2(Manacher算法)

    1089 最长回文子串 V2(Manacher算法)  基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 回文串是指aba.abba.cccbccc.aaa ...

随机推荐

  1. node升级7.0以上版本使用gulp时报错

    今天使用gulp时 ,出现了以下报错信息: Error: Cannot find module 'internal/fs'at Object.<anonymous> (/home/XXX/ ...

  2. hexo部署

    title: hexo 部署(一) date: 2018-09-16 18:01:26 tags: hexo部署配置 categories: 博客搭建 hexo博客搭建 折腾了好久的时间,终于使用he ...

  3. git拉代码,IntelliJ idea报错,cannot load module xxxxx

    1 从git上下工程的时候,IntelliJ idea报错,cannot load module xxxx VCS-git-clone-ssh:xxxx ,报错cannot load module x ...

  4. fastCMS数据库相关操作类

    fastCMS针对数据库的操作有以下几个类: 1.[paging_Class]分页类 此类用于分页检索数据库内符合条件的记录 1) 支持百万级数据分页 2) 支持多种类型的SQL语法,比如 Left ...

  5. TW实习日记:第七天

    今天早上,将项目的两个企业微信接口:登录和应用消息发送接口,做了最后的收尾工作,把目前我能解决的问题算是基本都解决了.早上还开了一个会,大意是组长封装了许多组件叫我们使用,在不断的使用中打磨组件的可用 ...

  6. Hands on Machine Learning with sklearn and TensorFlow —— 一个完整的机器学习项目(加州房地产)

    数据集地址:https://github.com/ageron/handson-ml/tree/master/datasets 先行知识准备:NumPy,Pandas,Matplotlib的模块使用 ...

  7. Professional Books

    Machine Learning:     Pattern Recognition and Machine Learning(PRML)    https://mqshen.gitbooks.io/p ...

  8. redis rdb aof比较

    Redis中数据存储模式有2种:cache-only,persistence; cache-only即只做为“缓存”服务,不持久数据,数据在服务终止后将消失,此模式下也将不存在“数据恢复”的手段,是一 ...

  9. Python3 匿名函数

    一 匿名函数 lambda函数也叫匿名函数,语法结构如下: lambda x:x+1 x --> 形参 x+1 --> 返回值,相当于return x+1 实例(Python3.0+): ...

  10. 20172330 2017-2018-1 《Java程序设计》第十周学习总结

    20172330 2017-2018-1 <程序设计与数据结构>第十周学习总结 教材学习内容总结 本周的学习内容为集合 集合 对象具有定义良好的接口,从而成为一种实现集合的完善体制. 动态 ...