【题目链接】

点击打开链接

【算法】

正反两遍EXKMP,即可

【代码】

#include<bits/stdc++.h>
using namespace std;
#define MAXC 26
#define MAXL 500010 int T,ans,tmp,i,len;
int a[MAXC+],Next[MAXL],extend1[MAXL],extend2[MAXL],sum[MAXL];
char s1[MAXL],s2[MAXL]; template <typename T> inline void read(T &x) {
int f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) { if (c == '-') f = -f; }
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
}
template <typename T> inline void write(T x) {
if (x < ) { putchar('-'); x = -x; }
if (x > ) write(x/);
putchar(x%+'');
}
template <typename T> inline void writeln(T x) {
write(x);
puts("");
}
inline void exkmp(char *s1,char *s2,int *Next,int *Extend) {
int i=,j,pos;
while (i + < len && s2[i+] == s2[i]) i++;
Next[] = i;
pos = ;
for (i = ; i < len; i++) {
if (i + Next[i-pos] < pos + Next[pos]) Next[i] = Next[i-pos];
else {
j = pos + Next[i-pos] - i;
if (j < ) j = ;
while (i + j < len && s2[j] == s2[i+j]) j++;
Next[i] = j;
pos = i;
}
}
i = ;
while (i < len && s1[i] == s2[i]) i++;
Extend[] = i;
pos = ;
for (i = ; i < len; i++) {
if (i + Next[i-pos] < pos + Extend[pos]) Extend[i] = Next[i-pos];
else {
j = pos + Extend[pos] - i;
if (j < ) j = ;
while (i + j < len && s1[i+j] == s2[j]) j++;
Extend[i] = j;
pos = i;
}
}
} int main() { read(T);
while (T--) {
for (i = ; i <= MAXC; i++) read(a[i]);
scanf("%s",s1);
len = strlen(s1);
sum[] = a[s1[]-'a'+];
for (i = ; i < len; i++) {
s2[len-i-] = s1[i];
if (i > ) sum[i] = sum[i-] + a[s1[i]-'a'+];
}
exkmp(s2,s1,Next,extend1);
exkmp(s1,s2,Next,extend2);
ans = ;
for (i = ; i < len - ; i++) {
tmp = ;
if (extend1[len-i-] == i + ) tmp += sum[i];
if (extend2[i+] == len - i - ) tmp += sum[len-] - sum[i];
ans = max(ans,tmp);
}
writeln(ans);
} return ; }

【HDU 3613】Best Reward的更多相关文章

  1. 【数位dp】【HDU 3555】【HDU 2089】数位DP入门题

    [HDU  3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #includ ...

  2. 【HDU 5647】DZY Loves Connecting(树DP)

    pid=5647">[HDU 5647]DZY Loves Connecting(树DP) DZY Loves Connecting Time Limit: 4000/2000 MS ...

  3. -【线性基】【BZOJ 2460】【BZOJ 2115】【HDU 3949】

    [把三道我做过的线性基题目放在一起总结一下,代码都挺简单,主要就是贪心思想和异或的高斯消元] [然后把网上的讲解归纳一下] 1.线性基: 若干数的线性基是一组数a1,a2,a3...an,其中ax的最 ...

  4. 【HDU 2196】 Computer(树的直径)

    [HDU 2196] Computer(树的直径) 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 这题可以用树形DP解决,自然也可以用最直观的方法解 ...

  5. 【HDU 2196】 Computer (树形DP)

    [HDU 2196] Computer 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 刘汝佳<算法竞赛入门经典>P282页留下了这个问题 ...

  6. 【HDU 5145】 NPY and girls(组合+莫队)

    pid=5145">[HDU 5145] NPY and girls(组合+莫队) NPY and girls Time Limit: 8000/4000 MS (Java/Other ...

  7. 【hdu 1043】Eight

    [题目链接]:http://acm.hdu.edu.cn/showproblem.php?pid=1043 [题意] 会给你很多组数据; 让你输出这组数据到目标状态的具体步骤; [题解] 从12345 ...

  8. 【HDU 3068】 最长回文

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=3068 [算法] Manacher算法求最长回文子串 [代码] #include<bits/s ...

  9. 【HDU 4699】 Editor

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=4699 [算法] 维护两个栈,一个栈放光标之前的数,另外一个放光标之后的数 在维护栈的同时求最大前缀 ...

随机推荐

  1. (47)C#运行时序列化

    序列化是将对象或对象图转化成字节流的过程.反序列化是将字节流转换回对象图的过程.

  2. easyui分页时,总页数出错

    错误出现 MyBatis用easyui写后台分页代码时,出现翻页后显示总页数错误 代码如下 可能原因在于后台mappers.xml里的sql语句错误 <select id="getPr ...

  3. argument to nsmutablearray method addobject cannot be nil 警告

    You cannot add nil to an NSMutableArray, and you will raise an exception if you try to. There's NSNu ...

  4. 【IntelliJ Idea】启动参数JVM参数的配置 优先级高于 application.yaml/application.properties中的配置,前者可以覆盖后者的配置

  5. 如何在ASP.NET Core自定义中间件中读取Request.Body和Response.Body的内容?

    原文:如何在ASP.NET Core自定义中间件中读取Request.Body和Response.Body的内容? 文章名称: 如何在ASP.NET Core自定义中间件读取Request.Body和 ...

  6. jQuery.ajax()方法中參数具体解析

    前言 在项目开发中,为了实现异步向服务端发起请求,最常常使用的就是jQuery.ajax方法了.刚開始需求比較简单,调用jQuery.ajax方法时要传的參数也就那几个常见的參数:url/data/d ...

  7. 大众车机天宝187A Hack笔记

    0×00前言 自从去年买了车,对汽车电子系统的兴趣就上来了.这不,前一阵子逛汽车论坛,发现了有网友将老版本的天宝车机被刷上了2017新帕萨特车机的系统,支持超级蓝牙和苹果CarPlay,百度CarLi ...

  8. Linux温习(三)Linux文件和文件夹管理

    关于Linux文件夹的几个常见概念 路径 对文件位置信息的描写叙述机制.是指从树型文件夹中的某个文件夹层次到其内某个文件的一条通路.分为相对路径和绝对路径: 工作文件夹 登入系统后.用户始终处于某个文 ...

  9. 与linux相处的日子里

    在前几天装了一下linux操作系统,并安装了几个经常使用的工具.如今就谈谈我的感受吧! 对一个连linux几个字母都不会拼写的人来说.让我參与这个工作可谓是:"太残忍啦!"当然这在 ...

  10. 【微信支付】分享一个失败的案例 跨域405(Method Not Allowed)问题 关于IM的一些思考与实践 基于WebSocketSharp 的IM 简单实现 【css3】旋转倒计时 【Html5】-- 塔台管制 H5情景意识 --飞机 谈谈转行

    [微信支付]分享一个失败的案例 2018-06-04 08:24 by stoneniqiu, 2744 阅读, 29 评论, 收藏, 编辑 这个项目是去年做的,开始客户还在推广,几个月后发现服务器已 ...