回文串---Hotaru's problem】的更多相关文章

HDU   5371 Description Hotaru Ichijou recently is addicated to math problems. Now she is playing with N-sequence. Let's define N-sequence, which is composed with three parts and satisfied with the following condition: 1. the first part is the same as…
题目地址:HDU 5371 题意:给你一个具有n个元素的整数序列,问你是否存在这样一个子序列.该子序列分为三部分,第一部分与第三部分同样,第一部分与第二部分对称.假设存在求最长的符合这样的条件的序列. 思路:用Manacher算法来处理回文串的长度,记录下以每个-1(Manacher算法的插入)为中心的最大回文串的长度. 然后从最大的開始穷举,仅仅要p[i]-1即能得出以数字为中心的最大回文串的长度,然后找到右边相应的'-1'.推断p[i]是不是大于所穷举的长度,假设当前的满足三段,那么就跳出,…
Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can find by performing this transformation. For example: Given "aacecaaa", return "aaacecaaa&qu…
题目链接:http://poj.org/problem?id=1159 题意:给定一个长度为N的字符串.问你最少要添加多少个字符才能使它变成回文串. 思路:最少要添加的字符个数=原串长度-原串最长回文子串长度.对于求原串最长回文子串长度用的是DP的经典问题LCS最长公共子序列的做法. 设原串为S,原串的逆串为S‘,那么原串的最长回文子串长度=S和S'的最长公共子序列长度. 由于N的范围最大是5000,所以5000*5000的数组开不下,所以需要用到滚动数组来求.[关于原串求最长回文子串用的Man…
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2342 思路:先跑一遍Manacher求出p[i]为每个位置为中心的回文半径,因为双倍回文串的长度一定是4的倍数,即偶数,那么对于Manacher的回文中心一定是'#'字符.所以我们枚举每个'#',对于每个'#'当回文半径大于等于4才有可能成为双倍回文.如果当前位置的i是'#'且满足以上条件.那么我们就找到i右边的j.因为双倍回文的长度是4的倍数,那么i右边的j的回文长度一定是2的倍数,即…
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2565 题意:中文题 思路:定义L[i],R[i].表示以i为左端点/右端点时,最长回文串长度.那么答案就是L[i]+R[i]的最大值.问题转化为怎么求L[i],R[i].我们通过用Manacher可以求出以i为中心的最长回文串半径.然后再通过暴力+剪枝的方法对于每一个i和对应的最长半径求更新L[i],R[i]. #include<iostream> #include<cstdio…
题目链接:http://poj.org/problem?id=3974 题意:求出给定字符串的最长回文串长度. 思路:裸的Manacher模板题. #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<algorithm> using namespace std; +; typedef long l…
http://www.lydsy.com/JudgeOnline/problem.php?id=3676 题意:给一个串求回文串×出现次数的最大值.(|S|<=300000) #include <bits/stdc++.h> using namespace std; const int N=300005; struct E { int f[N], c[N][26], l[N], last, s[N], n, cnt[N], tot; E() { f[0]=1; f[1]=0; l[1]=…
HDU   3613 Description After an uphill battle, General Li won a great victory. Now the head of state decide to reward him with honor and treasures for his great exploit. One of these treasures is a necklace made up of 26 different kinds of gemstones,…
HDU   3294 Problem Description One day, sailormoon girls are so delighted that they intend to research about palindromic strings. Operation contains two steps:First step: girls will write a long string (only contains lower case) on the paper. For exa…