[CodeForces - 447B] B - DZY Loves Strings
B - DZY Loves Strings
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter c DZY knows its value wc. For each special string s = s1s2... s|s|(|s| is the length of the string) he represents its value with a function f(s), where
Now DZY has a string s. He wants to insert k lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get?
Input
The first line contains a single string s (1 ≤ |s| ≤ 103).
The second line contains a single integer k (0 ≤ k ≤ 103).
The third line contains twenty-six integers from wa to wz. Each such number is non-negative and doesn't exceed 1000.
Output
Print a single integer — the largest possible value of the resulting string DZY could get.
Example
abc31 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
41
Note
In the test sample DZY can obtain "abcbbc", value = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41.
题目大意是,给你一个字符串,再给你一个可添加的字符数,然后给你一个公式,要使某个值最大化.
根据公式的特点,我们把ai最大的字符放在越后面输出越好,所以,会出现这种形式:
原串+n个ai最大的字符
那么就解决了.
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
],n,ans,x;
int main(){
];
scanf("%s",s);
scanf("%d",&n);
; i<; i++) scanf("%d",&a[i]),x=max(x,a[i]);
int len=strlen(s);
; i<len; i++) ans+=(i+)*a[s[i]-'a'];
; i++) ans+=(i+)*x;
printf("%d",ans);
;
}
[CodeForces - 447B] B - DZY Loves Strings的更多相关文章
- Codeforces Round #254 (Div. 1) D - DZY Loves Strings
D - DZY Loves Strings 思路:感觉这种把询问按大小分成两类解决的问题都很不好想.. https://codeforces.com/blog/entry/12959 题解说得很清楚啦 ...
- Codeforces Round #254 (Div. 1) D. DZY Loves Strings hash 暴力
D. DZY Loves Strings 题目连接: http://codeforces.com/contest/444/problem/D Description DZY loves strings ...
- Codeforces Round #FF (Div. 2):B. DZY Loves Strings
B. DZY Loves Strings time limit per test 1 second memory limit per test 256 megabytes input standard ...
- CF447B DZY Loves Strings 贪心
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter ...
- Codeforces 444 C - DZY Loves Colors
C - DZY Loves Colors 思路: 分块,复杂度有点玄学,和普通分块不同的是在这个块被一次染色的时候暴力染整个块. 代码: #pragma GCC optimize(2) #pragma ...
- [CodeForces - 447E] E - DZY Loves Fibonacci Numbers
E DZY Loves Fibonacci Numbers In mathematical terms, the sequence Fn of Fibonacci numbers is define ...
- [CodeForces - 447D] D - DZY Loves Modification
D - DZY Loves Modification As we know, DZY loves playing games. One day DZY decided to play with a n ...
- [CodeForces - 447C] C - DZY Loves Sequences
C - DZY Loves Sequences DZY has a sequence a, consisting of n integers. We'll call a sequence ai, ai ...
- [CodeForces - 447A] A - DZY Loves Hash
A - DZY Loves Hash DZY has a hash table with p buckets, numbered from 0 to p - 1. He wants to insert ...
随机推荐
- HDU 5245 Joyful(期望)
http://acm.hdu.edu.cn/showproblem.php?pid=5245 题意: 给出一个n*m的矩阵格子,现在有k次操作,每次操作随机选择两个格子作为矩形的对角,然后将这范围内的 ...
- 51nod 1615 跳跃的杰克
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1615 题意: 思路:一开始是觉得一旦超过了终点,中间某个地方往相反地方跳 ...
- MVC ---- 去掉HTML过滤
在方法头上添加特效 [ValidateInput(false)] 富文本框提交的内容就可以顺利提交到后台了.
- Codeforces 765 E. Tree Folding
题目链接:http://codeforces.com/problemset/problem/765/E $DFS子$树进行$DP$ 大概分以下几种情况: 1.为叶子,直接返回. 2.长度不同的路径长度 ...
- mysql索引使用
原文:http://www.jianshu.com/p/2b541c028157 索引是快速搜索的关键.MySQL索引的建立对于MySQL的高效运行是很重要的.下面介绍几种常见的MySQL索引类型.在 ...
- StringBuffer 清空StringBuffer的实例的三种方法
@Test public void testStringbuffer(){ //StringBuffer类没有clear方法,不过可以通过下面两种方法来清空一个StringBuffer的实例: Str ...
- oracle的批量操作sql语句
1.批量删除/批量更新 mapper: <update id="updatePrjStateByFPrjId" parameterType="string" ...
- 设计模式(八)Dynamic Proxy Parttern 动态代理模式
举例: jdk自带动态代理 javaassit字节码操作库实现 CGLIB ASM底层操作 实际例子: 使用jdk自带动态代理 java.lang.reflect.Proxy 作用 动态生成代理类和对 ...
- cocos2dx 编译遇到资源里有.svn文件不能删除报错的问题
使用cocos compile -p android 对项目进行编译的时候,遇到res文件中包含了只读属性的svn目录,不能进行删除而报错. 错误如下图(build_android.py里面对.svn ...
- 第 4 章 容器 - 028 - 限制容器对CPU的使用
限制容器对CPU的使用 默认设置下,所有容器可以平等地使用 host CPU 资源并且没有限制. Docker 可以通过 -c 或 --cpu-shares 设置容器使用 CPU 的权重.如果不指定, ...