51nod 1088 最长回文子串 【中心拓展法/输出长度和路径】


输入Str(Str的长度 <= 1000)
输出最长回文子串的长度L。
daabaac
5 [代码]:
#include<bits/stdc++.h> using namespace std;
#define N 550
int mp[N][N];
int main()
{
string s;
cin>>s;
int n=s.size();
int res=; for(int i=; i<n; i++){ for(int j=;(i-j)>=&&(i+j)<n; j++){
if(s[i-j]!=s[i+j]) break;
res=max(res,*j+);
} for(int j=;(i-j)>=&&(i+j+)<n; j++){
if(s[i-j]!=s[i+j+]) break;
res=max(res,*j+);
}
}
printf("%d\n",res);
}
输出长度
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define N 5050
int main()
{
string s;
int pos[];
cin>>s;
int res = , st=, ed=;
int n = s.size();
for(int i=;i<n;++i)
pos[i]=i;
for(int i=; i<n; i++) {
for(int j= ;(i-j)>=&&(i+j)<n ;j++) {
if(s[i-j]!=s[i+j]) break;
if(*j+>res){
res=*j+;
st=pos[i-j];
ed=pos[i+j];
}
} for(int j= ;(i-j)>=&&(i+j+)<n ;j++) {
if(s[i-j]!=s[i+j+]) break;
if(*j+>res){
res=*j+;
st=pos[i-j];
ed=pos[i+j+];
}
}
}
for(int i=st; i<=ed; i++)
cout<<s[i];
cout<<endl;
return ;
}
输出子串
51nod 1088 最长回文子串 【中心拓展法/输出长度和路径】的更多相关文章
- 51nod 1088 最长回文子串
1088 最长回文子串 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 回文串是指aba.abba.cccbccc.aaaa这种左右对称的字符串. 输入一 ...
- (最长回文子串 线性DP) 51nod 1088 最长回文子串
输入一个字符串Str,输出Str里最长回文子串的长度. 回文串:指aba.abba.cccbccc.aaaa这种左右对称的字符串. 串的子串:一个串的子串指此(字符)串中连续的一部分字符构成的子(字符 ...
- 51NOD 1088 最长回文子串&1089 最长回文子串 V2(Manacher算法)
回文串是指aba.abba.cccbccc.aaaa这种左右对称的字符串. 输入一个字符串Str,输出Str里最长回文子串的长度. Input 输入Str(Str的长度 <= 1000(第二题要 ...
- 51Nod 1089 最长回文子串 V2 —— Manacher算法
题目链接:https://vjudge.net/problem/51Nod-1089 1089 最长回文子串 V2(Manacher算法) 基准时间限制:1 秒 空间限制:131072 KB 分值: ...
- 【LeetCode】最长回文子串-中心扩展法
[问题]给定一个字符串 s,找到 s 中最长的回文子串.你可以假设 s 的最大长度为 1000. 示例 : 输入: "babad" 输出: "bab" 注意: ...
- 51nod 1089 最长回文子串 V2(Manacher算法)
回文串是指aba.abba.cccbccc.aaaa这种左右对称的字符串. 输入一个字符串Str,输出Str里最长回文子串的长度. 收起 输入 输入Str(Str的长度 <= 100000) ...
- 51nod(1089 最长回文子串 V2)(hash 加二分)
1089 最长回文子串 V2(Manacher算法) 回文串是指aba.abba.cccbccc.aaaa这种左右对称的字符串. 输入一个字符串Str,输出Str里最长回文子串的长度. 输入 ...
- 51nod 1089 最长回文子串 V2(Manacher算法)
基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 输入N求N的阶乘的10进制表示的长度.例如6! = 720,长度为3. Input 第1行:一个数T,表示后面用作输入 ...
- 51nod 1089最长回文子串V2 (manacher)
经典题 manacher是一种很神奇的算法, 算是动态规划的一种,不过利用的信息非常有效 #include <iostream> #include <cstdio> #incl ...
随机推荐
- 如何在 CentOS 7 上安装 Python 3
当前最新的 CentOS 7.5 默认安装的是 Python 2.7.5,并且默认的官方 yum 源中不提供 Python 3 的安装包.这里主要介绍两种在 CentOS 7 中安装 Python 3 ...
- 收集的免费API接口
1.IP地址调用接口 这是淘宝的IP调用API http://ip.taobao.com/service/getIpInfo.php?ip=$ip 返回值:{"code":0,&q ...
- python的标准模块
本文用于记录python中的标准模块,随时更新. decimal模块(解决小数循环问题): >>> import decimal >>> a = decimal.D ...
- LeetCode(290) Word Pattern
题目 Given a pattern and a string str, find if str follows the same pattern. Here follow means a full ...
- POJ:1086-Parencodings
Parencodings Time Limit: 1000MS Memory Limit: 10000K Description Let S = s1 s2-s2n be a well-formed ...
- 数据库导入Exel,输入到浏览器
db.php <?php require dirname(__FILE__)."/dbconfig.php";//引入配置文件 class db{ public $conn= ...
- Android SDK Manager 报错:Connection to https://dl-ssl.google.com refused
Connection to https://dl-ssl.google.com refused. OR Failed to fectch URl https://dl-ssl.google.com/a ...
- Mark Down 简单标记语言
MarkDown介绍=============== ## 1.标题分级介绍 #一级标题###三级标题######六级标题 一级标题============== 二级标题---------------- ...
- AtCoder Grand Contest 021
A - Digit Sum 2 Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem Statement Find t ...
- 读《MySql必知必会》笔记
MySql必知必会 2017-12-21 意义:记录个人不注意的,或不明确的,或不知道的细节方法技巧,此书250页 登陆: mysql -u root-p -h myserver -P 9999 SH ...