hdu3613】的更多相关文章

/** 题目: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)的算法求最长回文子串的做法获得…
题目链接: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…
#include<stdio.h> #include<string.h> #define maxn 501000 char s[maxn],t[maxn]; int next[maxn],extand1[maxn],extand2[maxn]; ],sum[maxn]; void getnext(int *next,char *t) { int i,k,j,len=strlen(t); next[]=len; i=; &&t[i]==t[i+]) { 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值). 根据上一篇文章我们可知…
题意: 将一段字符串 分割成两个串 如果分割后的串为回文串,则该串的价值为所有字符的权值之和(字符的权值可能为负数),否则为0. 问如何分割,使得两个串权值之和最大 思路: 裸的: 枚举分割点,计算,O(n) 判断是否回文 总复杂度O(n^2) 优化: 利用Manacher的预处理 O(1)判断是否回文 复杂度O(n) //Manacher /* ** 求最长回文子串 */ #include <cstdio> #include <cstring> #include <iost…
http://acm.hdu.edu.cn/showproblem.php?pid=3613 每个字符都有一个权值,将一个字符串分成两半,如果某一半是回文串就把所有的字符权值加起来,否则当0来处理,问最大值会是多少. 这题很明显是判断前后缀的回文串然后用O(n)的时间遍历取最大值. 问题在于如何判断是前后缀的最大回文串,对于回文串,就很自然而然的想到Manacher算法,对于每一个点,如果以它为中心的回文字符串和最前端接上,他就是一个前缀的回文串,如果和后面接上就是一个后缀的回文串,将所有的这些…
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…
题解: EX_KMP 网上似乎说kmp也可以,但是我交了一发代码没过 然后标记一下哪一些前缀和后缀会问 暴力枚举拆开了的位置 代码: #include<cstdio> #include<cmath> #include<algorithm> #include<cstring> using namespace std; ; ],n,nxt[N],match[N],exnxt[N],exmatch[N]; int L[N],R[N]; char s[N],t[N]…
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++)…
hdu4333 /* 题意:字符串s[0..n-1],每次把最后一个字符放到前面,求形成的字符串比最初串分别小,相同,大于的个数 因为是为了练习扩展KMP所以肯定是扩展KMP, 为了循环方便,在后面复制字符串,求出next[]数组后, 如果next[i]>n那么肯定相等,如果小于就判断s[ next[i] ]和 s[ i+next[i] ]的大小判断 trick:题目求得是形成的不同的字符串的个数,可以知道相等的字符串肯定只有一个, 而从0..n-1,第二个next[i]大于n那么这个i就是该字…
题目链接: https://cn.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 differe…
拓展KMP解决的问题是给两个串S和T,长度分别是n和m,求S的每一个后缀子串与T的最长公共前缀分别是多少,记作extend数组,也就是说extend[i]表示S[i,n-1](i从0开始)和T的最长公共前缀长度. 需要注意的是如果extend[i]=m,即S[i,n-1]和T的最长公共前缀长度是m(正好是T的长度),那么就表示T在S中找到匹配而且起始位置是i,这就解释了为什么这个算法叫做拓展KMP了. 其实大致和KMP有异曲同工之妙,都是匹配,都是借用一个next数组. 下面举一个例子,S=”a…
题目链接: https://cn.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 differe…
一. 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…
目的:线性查找一个串的最长回文子串 时间复杂度:O(n) len[i]表示以i为中心的回文串的半径,mx即为当前计算回文串最右边字符的最大值,p是中心点mid,mx-i和2*p-1关于p对称 https://blog.csdn.net/csdn_kou/article/details/82917937 hdu3068,板子题,求最长回文长度. #include<bits/stdc++.h> using namespace std; ; ]; ],T[maxn*],s[maxn*]; int i…
最近做完了kuangbin的一套关于kmp的题目(除了一道字典树的不会,因为还没学字典树所以先放放),做个总结.(kuangbin题目的链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=70325#problem/A) 说实话,kmp这个东西真的理解了很久,因为网上模板的下标都不一样,而且讲解的部分和代码实现又有点差别.话说当初看到一个比较好的博客忘记保存了..= = 首先给个最简单的题目:http://oj.acm.zstu.ed…
链接: 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…
题目:hdu3613: 题意:有26字母对应的价值,然后给出以个串,把它分成两段字串,如果字串是回文串,串的价值就是每个字符和,不是就为0.求最大价值. 博客 分析:拓展KMP的应用求回文字串. #include<iostream> #include<stdio.h> #include<algorithm> #include<string> #include<string.h> using namespace std; ; ],w[max_],…