[Manacher][HDU3613][Best Reward]】的更多相关文章

题意: 将一段字符串 分割成两个串 如果分割后的串为回文串,则该串的价值为所有字符的权值之和(字符的权值可能为负数),否则为0. 问如何分割,使得两个串权值之和最大 思路: 裸的: 枚举分割点,计算,O(n) 判断是否回文 总复杂度O(n^2) 优化: 利用Manacher的预处理 O(1)判断是否回文 复杂度O(n) //Manacher /* ** 求最长回文子串 */ #include <cstdio> #include <cstring> #include <iost…
题目链接:https://vjudge.net/problem/HDU-3613 Best Reward Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 3104    Accepted Submission(s): 1277 Problem Description After an uphill battle, General Li w…
/** 题目:hdu3613 Best Reward 链接:http://acm.hdu.edu.cn/showproblem.php?pid=3613 题意:有一个字符串,把他切成两部分. 如果这部分是回文串,那么他的值为所有字母的权值和.否则这部分值为0:这两部分的值和为该切法的权值. 求最大的切法的权值. 思路: 如果能够判断[0,i],[i,n-1]是一个回文串(0<=i<n)那么就可以枚举i,计算切割位置为i时候两部分的贡献和. 取最大的. 利用O(n)的算法求最长回文子串的做法获得…
Best Reward Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 4345    Accepted Submission(s): 1791 Problem Description After an uphill battle, General Li won a great victory. Now the head of state…
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, and the length of the…
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, and the length of the…
先manacher.然后前缀和价值,枚举切点,O(1)判断切后是否回文 #include <iostream> #include <cstring> #include <cstdio> using namespace std; int T, val[1000005], p[1000005], len, w[255]; char a[1000005]; void manacher(){ int mx=0, id=0; for(int i=1; i<len; i++)…
题意: 将一段字符串 分割成两个串 如果分割后的串为回文串,则该串的价值为所有字符的权值之和(字符的权值可能为负数),否则为0. 问如何分割,使得两个串权值之和最大 思路: 首先了解扩展kmp 扩展KMP:给出模板串A和子串B,长度分别为lenA和lenB,要求在线性时间内,对于每个A[i](0<=i<=lenA-1),求出A[i..lenA-1]与B的最长公共前缀长度,记为ex[i](或者说,ex[i]为满足A[i..i+z-1]==B[0..z-1]的最大的z值). 根据上一篇文章我们可知…
一. KMP 1 找字符串x是否存在于y串中,或者存在了几次 HDU1711 Number Sequence HDU1686 Oulipo HDU2087 剪花布条 2.求多个字符串的最长公共子串 POJ3080 Blue Jeans HDU1238 Substrings 3.next数组的应用 1) 求循环节 HDU3746 Cyclic Nacklace HDU1358 Period POJ2406 Power Strings HDU3374 String Problem 2) 利用next…
链接: https://vjudge.net/problem/HDU-3613 题意: 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 differen…