博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu3613Best Reward
阅读量:5286 次
发布时间:2019-06-14

本文共 3277 字,大约阅读时间需要 10 分钟。

题解:  考虑用ex_kmp维护出当前位置后缀和前缀是否是回文串即可  前缀和统计价值

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define mp make_pair#define pb push_back#define pii pair
#define link(x) for(edge *j=h[x];j;j=j->next)#define inc(i,l,r) for(int i=l;i<=r;i++)#define dec(i,r,l) for(int i=r;i>=l;i--)const int MAXN=5e5+10;const double eps=1e-8;#define ll long longusing namespace std;struct edge{int t,v;edge*next;}e[MAXN<<1],*h[MAXN],*o=e;void add(int x,int y,int vul){o->t=y;o->v=vul;o->next=h[x];h[x]=o++;}ll read(){ ll x=0,f=1;char ch=getchar(); while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();} while(isdigit(ch))x=x*10+ch-'0',ch=getchar(); return x*f;}int key[26],sum[MAXN],nxt[MAXN];char str[MAXN],s1[MAXN],s2[MAXN];void ex_next(int ex_Nxt[],char a[]){ int len=strlen(a); ex_Nxt[0]=len; int id_max=1; int t=0; while(t
=p){ int j=(p-k+1)>0?p-k+1:0; while(j+k
=p){ int j=(p-i+1)>0?p-i+1:0; while(j+i

 

        Best Reward

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 4245    Accepted Submission(s): 1737

Problem 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, and the length of the necklace is n. (That is to say: n gemstones are stringed together to constitute this necklace, and each of these gemstones belongs to only one of the 26 kinds.)
In accordance with the classical view, a necklace is valuable if and only if it is a palindrome - the necklace looks the same in either direction. However, the necklace we mentioned above may not a palindrome at the beginning. So the head of state decide to cut the necklace into two part, and then give both of them to General Li.
All gemstones of the same kind has the same value (may be positive or negative because of their quality - some kinds are beautiful while some others may looks just like normal stones). A necklace that is palindrom has value equal to the sum of its gemstones' value. while a necklace that is not palindrom has value zero.
Now the problem is: how to cut the given necklace so that the sum of the two necklaces's value is greatest. Output this value.
 

 

Input
The first line of input is a single integer T (1 ≤ T ≤ 10) - the number of test cases. The description of these test cases follows.
For each test case, the first line is 26 integers: v
1, v
2, ..., v
26 (-100 ≤ v
i ≤ 100, 1 ≤ i ≤ 26), represent the value of gemstones of each kind.
The second line of each test case is a string made up of charactor 'a' to 'z'. representing the necklace. Different charactor representing different kinds of gemstones, and the value of 'a' is v
1, the value of 'b' is v
2, ..., and so on. The length of the string is no more than 500000.
 

 

Output
Output a single Integer: the maximum value General Li can get from the necklace.
 

 

Sample Input
2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 aba 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 acacac
 

 

Sample Output
1 6
 

 

Source

转载于:https://www.cnblogs.com/wang9897/p/9821271.html

你可能感兴趣的文章
Modulation of Lipid Metabolism by Celastrol (文献分享一组-赵倩倩)
查看>>
HDU 1044 Collect More Jewels(BFS+DFS)
查看>>
TrackbarCallback 回调函数必须为 void(int,void*)
查看>>
【BZOJ1857】[Scoi2010]传送带 三分法
查看>>
JPA与Spring2.5整合时发生不能创建entityManagerFactory的问题解决方法
查看>>
FastDFS 初始
查看>>
选项卡
查看>>
14-----定时器
查看>>
XidianOJ 1028 数字工程
查看>>
派遣函数
查看>>
教程6--配置ssh
查看>>
C#串口扫描枪的简单实现
查看>>
SharePoint各版本信息
查看>>
Python数据结构——散列表
查看>>
.Net学习笔记----2015-07-08(基础复习和练习03)
查看>>
IDEA 中Spark SQL通过JDBC连接mysql数据库
查看>>
组合数学之母函数问题
查看>>
JavaScript创建对象之单例、工厂、构造函数模式
查看>>
CodeForces1154F
查看>>
TLS 9.2C
查看>>