CF932G-Palindrome Partition【PAM】】的更多相关文章

正题 题目链接:https://www.luogu.com.cn/problem/CF932G 题目大意 给出一个长度为\(n\)的字符串,将其分为\(k\)段(\(k\)为任意偶数),记为\(p\).要求满足对于任意\(i\)都有\(p_i=p_{k-i+1}\).求方案数. \(1\leq n\leq 10^6\) 解题思路 考虑将字符串化为\(S_1S_nS_2S_{n-1}S_3S_{n-2}...\)这样的形式,可以发现对于原本相同的段在这里就被表示为了一个偶回文子串. 那么问题就变为…
CF932G Palindrome Partition(回文自动机) Luogu 题解时间 首先将字符串 $ s[1...n] $ 变成 $ s[1]s[n]s[2]s[n-1]... $ 就变成了求将字符串全部划分为偶回文串的方案数. 建回文树大力跳$ fail $ 直接 $ dp $ 的复杂度是十分优秀的 $ O ( n ^ {2} ) $. 优化不容易想到. 考虑字符串上第 $ j $ 位为结尾的所有回文子串,毫无疑问它们在树上是一条链. 但它有个更重要的性质. 其中所有长度 $ > j…
680. Valid Palindrome II[easy] Given a non-empty string s, you may delete at most one character. Judge whether you can make it a palindrome. Example 1: Input: "aba" Output: True Example 2: Input: "abca" Output: True Explanation: You co…
之前创建asm磁盘的时候总结过一下错误:http://blog.csdn.net/rhys_oracle/article/details/17029333 当今天情况是这种.例如以下: 在使用openfiler通过iSCSI映射到本地,发现将整个磁盘创建为asm提演示样例如以下错误: [root@rac1 iscsi]# /etc/init.d/oracleasm createdisk VOL1 /dev/sdh Marking disk "VOL1" as an ASM disk:…
题目链接:uva 12050 - Palindrome Numbers 题意:求第n个回文串 思路:首先可以知道的是长度为k的回文串个数有9*10^(k-1),那么依次计算,得出n是长度为多少的串,然后就得到是长度为多少的第几个的回文串了,有个细节注意的是, n计算完后要-1! 下面给出AC代码: #include <bits/stdc++.h> typedef long long ll; using namespace std; ; ll num[maxn]; int n,ans[maxn]…
思路 首先把字符串变为\(S[1]S[n]s[2]s[n-1] \dots\) 这样原来的一个合法的划分方案就变成了用k个长度为偶数的回文子串划分的方案, 然后直接DP,对i位置,可转移的位置就是它的几个回文后缀,在PAM上跳fail即可 但是复杂度是假的,一旦串的每个字符都相同,就需要跳\(O(n)\)次fail,总复杂度变成了\(O(n^2)\) 所以有这样一个性质,对一个节点x,它的所有fail的len最多是log个等差数列,因为对于长度大于\(\frac{len}{2}\)的情况,由于回…
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6300 Triangle Partition Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others)Total Submission(s): 2964    Accepted Submission(s): 1474Special Judge Problem Description Chia…
Given a non-empty string s, you may delete at most one character. Judge whether you can make it a palindrome. Example 1: Input: "aba" Output: True Example 2: Input: "abca" Output: True Explanation: You could delete the character 'c'. N…
Check a positive number is a palindrome or not. A palindrome number is that if you reverse the whole number you will get exactly the same number. Notice It's guaranteed the input number is a 32-bit integer, but after reversion, the number may exceed…
回文自动机模板 1.一个串的本质不同的回文串数量是\(O(n)\)级别的 2.回文自动机的状态数不超过串长,且状态数等于本质不同的回文串数量,除了奇偶两个根节点 3.如何统计所有回文串的数量,类似后缀自动机,不需要重新拓扑排序,因为是按节点顺序插入的,所以逆序上传即可 建树的时候\(0\)节点为偶数长度回文的根 \(1\)节点为奇数长度回文的根 //#pragma GCC optimize("O3") //#pragma comment(linker, "/STACK:102…
正题 题目链接:https://www.luogu.com.cn/problem/P3649 题目大意 一个字符串,求最大的回文串长度×出现次数 解题思路 构建出\(\text{PAM}\)然后统计一下每个节点作为后缀的次数,\(fail\)树上上传一下信息就好了,时间复杂度\(O(n)\). 当然也可以\(\text{SAM}+\text{Manacher}+\)倍增,因为一个字符串里本质不同的回文串就是会让马拉车的\(maxright\)增加的回文串,这些最多只有\(n\)个,马拉车跑出来的…
题目链接 https://open.kattis.com/problems/names 题意 给出一个字符串 有两种操作 0.在字符串的最末尾加一个字符 1.更改字符串中的一个字符 求最少的操作步数使得字符串变成回文串 思路 由于回文串具有对称关系 所以给出一串回文串 最多的操作步数 就是 len / 2 只改一半不同的字符就可以了 所以我们可以先将字符串倒置 然后依次一步一步 挪过去 与原串比较 比出有多少个不同的字符 那么操作次数就是 挪位数+不同字符个数/ 2 比如说 样例 kaia ai…
[208]Implement Trie (Prefix Tree) (2018年11月27日) 实现基本的 trie 树,包括 insert, search, startWith 操作等 api. 题解:<程序员代码面试指南>chp5, 最后一题. 里面讲了怎么实现.这个就看代码吧.没啥好说的了. class Trie { public: /** Initialize your data structure here. */ Trie() { root = new TrieNode(); }…
[1]Two Sum (2018年11月9日,k-sum专题,算法群衍生题) 给了一个数组 nums, 和一个 target 数字,要求返回一个下标的 pair, 使得这两个元素相加等于 target . 题解:我这次最大范围的优化代码, hash-table + one pass,时间复杂度 O(N),空间复杂度 O(N).重点在于动态找,一边生成hash-table的同时去找答案,不是先生成hash-table再开始找答案. //这种类似 hash 的能用 unordered_map 就不要…
[94]Binary Tree Inorder Traversal [95]Unique Binary Search Trees II (2018年11月14日,算法群) 给了一个 n,返回结点是 1 - n 的所有形态的BST. 题解:枚举每个根节点 r, 然后递归的生成左右子树的所有集合,然后做笛卡尔积. /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * Tr…
[10]Regular Expression Matching [17]Letter Combinations of a Phone Number [22]Generate Parentheses (2019年2月13日) 给了一个N,生成N对括号的所有情况的字符串. n = 3 [ "((()))", "(()())", "(())()", "()(())", "()()()" ] 题解:dfs生成. c…
[CF932G]Palindrome Partition(回文树,动态规划) 题面 CF 翻译: 给定一个串,把串分为偶数段 假设分为了\(s1,s2,s3....sk\) 求,满足\(s_1=s_k,s_2=s_{k-1}......\)的方案数 题解 反正我是不会做 基本就是照着\(laofu\)的打了一遍(laofu太强啦) 这题分成了两个步骤 如果直接分\(k\)段我们是没法直接判断的 假设两段\(s_i,s_{k-i+1}\) 因为\(s_i=s_{k-i+1}=x_1x_2.....…
[CF932G]Palindrome Partition 题意:给你一个字符串s,问你有多少种方式,可以将s分割成k个子串,设k个子串是$x_1x_2...x_k$,满足$x_1=x_k,x_2=x_{k-1}...x_i=x{k-i+1}$. $|s|\le 10^6$ 题解:设字符串的长度为n,考虑字符串$T=s_1s_ns_2s_{n-1}...$.问题就转化成了:求将原串划分成若干个长度为偶数的回文子串的方案数. 首先我们有一种暴力的想法,设f[i]表示将前i个字符分成若干个回文子串的方…
[题目] 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",…
234. Palindrome Linked List[easy] Given a singly linked list, determine if it is a palindrome. Follow up:Could you do it in O(n) time and O(1) space? 解法一: /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * Lis…
561. Array Partition I[easy] Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), ..., (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as large as possible. Example 1: Inpu…
125. Valid Palindrome[easy] Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a palindrome. No…
[题目] Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the original relative order of the nodes in each of the two partitions. For example,Given 1->4->3-…
[CF830C]Bamboo Partition 题解:给你n个数a1,a2...an和k,求最大的d使得$\sum\limits_{i=1}^n((d-a[i] \% d) \% d) \le k$ n<=100,a[i]<=10^9,k<=10^11 题解:$\sum\limits_{i=1}^n((d-a[i] \% d) \% d)=d\sum\limits_{i=1}^n{\lceil {a[i]\over d}\rceil }-\sum\limits_{i=1}^na[i]$…
题目等级:Easy 题目描述: Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward. Example 1: Input: 121 Output: true Example 2: Input: -121 Output: false Explanation: From left to right, it reads -12…
[题解]Palindrome pairs [Codeforces159D] 传送门:\(Palindrome\) \(pairs\) \([CF159D]\) [题目描述] 给定一个长度为 \(N\) 的字符串 \(S\),求有多少四元组 \((l_1,r_1,l_2,r_2)\) 满足 \(1 \leqslant l_1 \leqslant r_1 \leqslant l_2 \leqslant r_2 \leqslant N\) 且 \(S[l1...r1],\) \([Sl2...r2]\…
Difficulty:easy  More:[目录]LeetCode Java实现 Description https://leetcode.com/problems/valid-palindrome-ii/ Given a non-empty string s, you may delete at most one character. Judge whether you can make it a palindrome. Example 1: Input: "aba" Output…
[LeetCode]86. Partition List 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.me/ 题目地址:https://leetcode.com/problems/partition-list/description/ 题目描述: Given a linked list and a value x, partition it such that all no…
题目描述:两句话发人深思啊.... Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), ..., (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as large as possible. 感觉题目的大致意思就是把数组分成很多个二元数组,对它…
题意:对一个字符串进行插入删除等操作使其变成一个回文串,但是对于每个字符的操作消耗是不同的.求最小消耗. 思路: 我们定义dp [ i ] [ j ] 为区间 i 到 j 变成回文的最小代价.那么对于dp[i][j]有三种情况首先:对于一个串如果s[i]==s[j],那么dp[i][j]=dp[i+1][j-1]其次:如果dp[i+1][j]是回文串,那么dp[i][j]=dp[i+1][j]+min(add[i],del[i]):最后,如果dp[i][j-1]是回文串,那么dp[i][j]=d…