[BZOJ5330][SDOI2018]反回文串】的更多相关文章

luogu bzoj sol 枚举一个长度为\(n\)为回文串,它的所有循环位移都可以产生贡献. 但是这样算重了.重复的地方在于可能多个回文串循环同构,或者可能有的回文串经过小于\(n\)次循环位移后能够得到自身. 一个比较好的处理方式是:对每个回文串求最小的\(x\)使这个串经过\(x\)次循环位移后可以再次成为一个回文串.这样对每个回文串求\(\sum x\)显然就不会算重了. 考虑一个串的\(x\)是什么.显然会和这个串的最小循环节长度有关.实际上如果最小循环节长度为偶数,那么\(x\)就…
题目链接 (BZOJ) https://www.lydsy.com/JudgeOnline/problem.php?id=5330 (Luogu) https://www.luogu.org/problem/P4607 题解 首先观察一些性质. 一个回文串可以轮换产生多少个本质不同的串?周期那么多个. 可是有一种特殊情况,就是对于长度为偶数的回文串\(a=ss^Rss^Rss^R...ss^R\) (\(s^R\)表示\(s\)的reverse), 如果轮换位数恰好等于周期的一半,那么会产生\(…
题意 问有多少个长度为\(N\)且字符集大小为\(K\)的字符串可以通过回文串旋转 (把第一个字符移到最后)若干次得到.\(K\le N≤10^{18}\) 做法 ARC64F的加强版 设\(h(d)=d~is~odd?d:\frac{d}{2}\),\(f(d)\)为最小周期为\(i\)的回文串 有\(g(d)=K^{\left\lceil\frac{d}{2}\right\rceil}=\sum\limits_{i|d}f(i)\) 反演一下有:\(f(n)=\sum\limits_{d|n…
传送门 怎么说呢,一道不可多得的反演题吧,具体解释之后再补 #include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i=a;i<=b;++i) typedef long long ll; ; ll mul(ll x,ll y,ll p) { x%=p; y%=p; return (x*y-(ll)((long double)x/p*y+0.5)*p+p)%p; } ll _pow(ll x,ll n…
题意 给你一个正整数 \(n\),求有多少字符集为 \(1\) 到 \(k\) 之间整数的字符串,使得该字符串可以由一个长度为 \(n\) 的回文串循环移位得到. ARC原题 \(100\%\) 的数据是 \(n,k\le 10^9\) SDOI改编后,\(30\%\) 的数据是 \(n,k\le 10^{10}\),\(60\%\) 的数据是 \(n,k\le 10^{14}\),\(100\%\) 的数据是 \(n,k\le 10^{18}\)-- 题解 \(n,k\le 10^{10}\)…
题目大意: 求字符集大小为$k$长度为$n$的经循环移位后为回文串的数量. 题解: 这题是D1里最神的吧 考虑一个长度为$n$回文串,将其循环移位后所有的串都是满足要求的串. 但是显然这样计算会算重.考虑什么情况下会算重. 即当我们将这个回文串移位$x$后,发现这个新字符串为一个回文串时,必然接下来的移位都是重复的. 那么当$x$为多少时,新字符串为一个回文串? 我们稍加分析就会发现x一定和回文串的最小循环节$d$有关. 考虑最小循环节若为偶数时,当$x==d/2$时,则会变为一个新的回文串.…
参考ARC064F 令$h(n)=\begin{cases}n(n为奇数)\\\frac{n}{2}(n为偶数)\end{cases}$,$f(n)$定义与ARC064F相同,答案即$\sum_{d|n}h(d)f(d)$ 考虑$f(n)$的转移,即$\sum_{d|n}f(d)=k^{\lceil\frac{n}{2}\rceil}$,将后者记作$g(n)$,即$(f*1)(x)=g(x)$,那么$(g*\mu)(x)=f(x)$,代入即得到$f(n)=\sum_{d|n}\mu(\frac{…
Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters. This is case sensitive, for example "Aa" is not considered a palindrome here. Note: Assume the leng…
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…
Given a string s, partition s such that every substring of the partition is a palindrome. Return the minimum cuts needed for a palindrome partitioning of s. For example, given s = "aab", Return 1 since the palindrome partitioning ["aa"…
Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. For example, given s = "aab",Return [ ["aa","b"], ["a","a","…
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring. 这道题让我们求最长回文子串,首先说下什么是回文串,就是正读反读都一样的字符串,比如 "bob", "level", &q…
考虑每个回文串,它一定是它中心字母的最长回文串两侧去掉同样数量的字符后的一个子串. 所以我们可以用manachar求出每一位的回文半径,放到哈希表里并标记出它的下一个子串. 最后拓扑排序递推就行了... 这道题丧心病狂卡哈希....wa了一屏... #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<queue> #include&l…
3676: [Apio2014]回文串 Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 2013  Solved: 863[Submit][Status][Discuss] Description 考虑一个只包含小写拉丁字母的字符串s.我们定义s的一个子串t的“出 现值”为t在s中的出现次数乘以t的长度.请你求出s的所有回文子串中的最 大出现值. Input 输入只有一行,为一个只包含小写字母(a -z)的非空字符串s. Output 输出一个整数…
题意:给你一个n*n (n<=200)的字符串矩阵,问你每行每列都是回文串的最大的m*m的矩阵是多少 题解:首先答案不满足单调性,即m成立而m-1与m+1都却不一定成立,所以必须枚举答案确定现在的值是否成立,从大到小枚举就好 当枚举值为k时就转换为判断k是否为所求矩阵,判断时我们需要枚举每个点,(看从这个点开始是否向右向下都有连续k个回文串) 而我们可以分别找向右和向下,标记这个点向右或向下是否满足(从这个点开始是否向右向下都有连续k个回文串) 我们找向下时枚举每列每个向右k个字符是否为回文串…
先要搞明白:最长公共子串和最长公共子序列的区别.    最长公共子串(Longest Common Substirng):连续 最长公共子序列(Longest Common Subsequence,LCS):不必连续   实在是汗颜,网上做一道题半天没进展: 给定一个字符串s,你可以从中删除一些字符,使得剩下的串是一个回文串.如何删除才能使得回文串最长呢?输出需要删除的字符个数. 首先是自己大致上能明白应该用动态规划的思想否则算法复杂度必然过大.可是对于回文串很难找到其状态和状态转移方程,换句话…
题目大意:给出一个字符串,求其回文串的长度.有多组数据. 分析:manacher算法模板题. //在原字符串两边和中间插入一个从未出现的字符,比如‘#’.然后再在最前面插入一个‘*’.#include<iostream> #include<cstdio> #include<cstring> using namespace std; #define MAXN 230005 char s1[MAXN],s2[MAXN]; int ans,p[MAXN],maxid,len;…
/* 题意:给出一串字符(全部是小写字母),添加或删除一个字符,都会产生一定的花费. 那么,将字符串变成回文串的最小花费是多少呢? 思路:如果一个字符串增加一个字符 x可以形成一个回文串,那么从这个字符串中删除这个字符 x 同样也能形成回文串! 所以我们只记录删除,和增加这个字符 x 的最小的费用就好了!->转变成添加多少个字符形成回文串费用最少! str[i]!=str[k] dp[i][j]=min(dp[i][j-1]+cost[str[k]-'a'], dp[i+1][j-1]+cost…
原题: http://acm.hdu.edu.cn/showproblem.php?pid=5651 很容易看出来的是,如果一个字符串中,多于一个字母出现奇数次,则该字符串无法形成回文串,因为不能删减字母. 当能构成回文串时,我们只需考虑这个回文串左半部分的情况,所以这个问题也就变成了求一半字符串的有重复的全排列. 因为应用全排列公式中,会用大数除以大数再取余,除法不能简单的分子.分母取余再做除法,这时就要用到乘法逆元,同时用费马小定理求乘法逆元 相关公式:http://www.cnblogs.…
题目链接: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…
题意:求不同回文串的个数 n<=10^5 题解: 先按照manacher的构造方法改造一遍串,然后跑一遍manacher. 如ababa--> $#a#b#a#b#a#@ 然后跑一遍后缀数组. 对于一个后缀sa[i]~cl(cl为字符串的总长),我们本来是要加上以sa[i]为中心的回文串的个数p[sa[i]]. 但是这可能有重复! 我们可以维护一个tmp,也就是上图中蓝色的框.tmp表示以字符sa[i-1]为中心已经被统计过的回文串的个数. 到了当前的sa[i],tmp=min(tmp,h[i…
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]=…
求最长回文串的利器 - Manacher算法 Manacher主要是用来求某个字符串的最长回文子串. 不要被manacher这个名字吓倒了,其实manacher算法很简单,也很容易理解,程序短,时间复杂度为O(n). 求最长回文子串这个问题,我听说有个分治+拓展kmp的算法,后缀数组也可以. 但是对于求回文串来说,manacher算法肯定有很多其他算法没有的优点. 现在进入正题: 首先,在字符串s中,用rad[i]表示第i个字符的回文半径,即rad[i]尽可能大,且满足: s[i-rad[i],…
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   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   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…
POJ   3974 Description Andy the smart computer science student was attending an algorithms class when the professor asked the students a simple question, "Can you propose an efficient algorithm to find the length of the largest palindrome in a string…