题目描述

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.

输入描述:

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 a single Integer: the maximum value General Li can get from the necklace.
示例1

输入

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

输出

1
6
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<iomanip>
#define INF 99999999
using namespace std;const int MAX=500000+10;
char s[MAX*2];
int p[MAX*2],sum[MAX],val[27];
int per[MAX],pos[MAX];int main(){int n;cin>>n;while(n--){for(int i=0;i<26;++i)scanf("%d",&val[i]);scanf("%s",s);int len=strlen(s),id=0,ans=-INF,temp=0;for(int i=1;i<=len;++i)sum[i]=sum[i-1]+val[s[i-1]-'a'];for(int i=len;i>=0;--i){s[i+i+2]=s[i];s[i+i+1]='#';}s[0]='*';for(int i=2;i<len+len+1;++i){if(p[id]+id>i)p[i]=min(p[2*id-i],p[id]+id-i);else p[i]=1;while(s[i-p[i]] == s[i+p[i]])++p[i];if(id+p[id]<i+p[i])id=i;if(i-p[i] == 0)per[p[i]-1]=n+1;if(i+p[i] == len+len+2)pos[p[i]-1]=n+1;}for(int i=1;i<len;++i){if(per[i] == n+1)temp+=sum[i];if(pos[len-i] == n+1)temp+=sum[len]-sum[i];if(temp>ans)ans=temp;temp=0;}cout<<ans<<endl;}return 0;
}

Best Reward相关推荐

  1. 过程即奖励(The Journey is the Reward)

    今天读完了<乔布斯传>.翻着这本书最后的影集,乔布斯传奇一生的一幕幕仿佛在眼前展开.从第一张照片中特里独行.桀骜不驯的年轻人,到最后一张照片中阳光下慈祥微笑的老者,看到的仿佛不是乔布斯的照 ...

  2. 扩展KMP --- HDU 3613 Best Reward

    Best Reward Problem's Link:   http://acm.hdu.edu.cn/showproblem.php?pid=3613 Mean: 给你一个字符串,每个字符都有一个权 ...

  3. HDU 3613 Best Reward 正反两次扩展KMP

    题目来源:HDU 3613 Best Reward 题意:每一个字母相应一个权值 将给你的字符串分成两部分 假设一部分是回文 这部分的值就是每一个字母的权值之和 求一种分法使得2部分的和最大 思路:考 ...

  4. Hdu - 2647 - Reward

    上题目 Reward Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  5. 【李宏毅2020 ML/DL】P115-117 Actor-Critic Sparse Reward Imitation Learning

    我已经有两年 ML 经历,这系列课主要用来查缺补漏,会记录一些细节的.自己不知道的东西. 关于强化学习,我专门花半年时间学习实践过,因此这里笔记只记录李老师的 outline .我的强化学习资源仓库: ...

  6. 【Reward is enough】Sutton、DavidSilver师徒联手:奖励机制足够实现各种目标。

    深度强化学习实验室 官网:http://www.neurondance.com/ 论坛:http://deeprl.neurondance.com/ 作者:小舟.陈萍 文章来源:转载自机器之心(链接文 ...

  7. 初探强化学习(10)强化学习中的一些术语(non-stationray,sample efficiency,planning和Learnin,Reward,off-policy和on-policy )

    1. 关于stationray 参考博客. Stationary or not 根据环境是否稳定.可以将强化学习问题分为stationary.non-stationary. 1.1 stationar ...

  8. InstructGPT高效实践——【DeepSpeed-Chat】源码详解(2/3):Supervised Finetuning、Reward Model Finetuning

    目录 前言 1 phase-1: Supervised Finetuning 1.1 训练数据样例 1.2 训练过程 1.3 关键代码详解 1.3.1 基座模型结构 1.3.2 LoRA结构及其正向传 ...

  9. AWS DeepRacer re:Invent 2018赛道reward function奖励函数

    我的新书<Android App开发入门与实战>已于2020年8月由人民邮电出版社出版,欢迎购买.点击进入详情 文章目录 1.回顾 2.re:Invent 2018赛道 3.策略 4.re ...

  10. 深度强化学习系列: “奖励函数”的设计和设置(reward shaping)

    概述 前面已经讲了好几篇关于强化学习的概述.算法(DPG->DDPG),也包括对环境OpenAI gym的安装,baseline算法的运行和填坑,虽然讲了这么多,算法也能够正常运行还取得不错的效 ...

最新文章

  1. Python全栈开发,Day1 - Python基础1
  2. 2016年宜昌楼市将迎来史上最激烈一战
  3. 对象级别锁 vs 类级别锁 – Java
  4. 当代成年人的生活状态......
  5. 网管实战之使用RSA实现企业安全访问
  6. 共享单车扫不开却自动计费 行程显示骑到非洲:想要带你一起去旅行?
  7. pip: command not found
  8. 上海计算机一级填空题,上海市计算机一级考试填空题.doc
  9. logstash 收集windows日志--解决日志不能重命名问题
  10. java注释 加粗_Java绘图技术,swing画图工具,文字,图片素材,注释,个人理解,星空等【诗书画唱】...
  11. 经典卷积神经网络——VGG16
  12. 采用Java+SSH+JSP技术架构开发实现在线会议租赁管理系统
  13. ros软路由防火墙(双线路、日志配置)
  14. ps怎么撤销参考线_ps里怎么把参考线去掉
  15. 关于微服务中用户身份认证的一点愚见
  16. Lingo 简单的背包问题
  17. 解决Could not resolve XXX
  18. 各种HIC处理数据之间的相互转化
  19. 洗扑克牌 (乱数排序)
  20. 【战神引擎】一键打开所有修改路径快捷方式

热门文章

  1. HTML基础教程 表格
  2. python怎么打开npz文件_numpy的文件存储.npy .npz 文件详解
  3. Linux下使用Mysql 第一天
  4. 24.WEB安全基础环境搭建 WIN7物理机的环境搭建
  5. 互联网思维——大数据思维
  6. 鼓励参与计算机考试宣传标语,考试考场宣传标语横幅大全
  7. 2020腾讯暑期游戏客户端实习面经(已OC)
  8. 重装ubuntu的流程整理
  9. 计算机vb实验感想,VB学习心得体会
  10. 在Ubuntu中使用天翼无线宽带