CodeForces 447B---DZY Loves Strings
2016-04-20 21:43
337 查看
C - DZY Loves Strings
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Submit
Status
Practice
CodeForces 447B
Description
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.
Sample Input
Input
abc
3
1 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
Output
41
Hint
In the test sample DZY can obtain “abcbbc”, value = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41.
水题,直接做~~~
仅代表个人观点,欢迎交流探讨,勿喷~~~
![](http://img.blog.csdn.net/20160420214303102)
PhotoBy:WLOP
http://weibo.com/wlop
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Submit
Status
Practice
CodeForces 447B
Description
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.
Sample Input
Input
abc
3
1 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
Output
41
Hint
In the test sample DZY can obtain “abcbbc”, value = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41.
水题,直接做~~~
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int v[30]; int main() { string a; cin>>a; int k; int sum=0; scanf("%d",&k); int maxn; for(int i=1;i<=26;i++) { cin>>v[i]; } maxn=*max_element(v,v+26); int l=a.length(); for(int i=1;i<=l;i++) { for(int j=1;j<=26;j++) { if((j-1)==a[i-1]-'a') { sum+=v[j]*i; break; } } } for(int i=l+1;i<=l+k;i++) { sum+=maxn*i; } cout<<sum<<endl; return 0; }
仅代表个人观点,欢迎交流探讨,勿喷~~~
PhotoBy:WLOP
http://weibo.com/wlop
相关文章推荐
- 站立会议第三天
- 第五周总结
- Eclipse转成Android Studio项目想要添加依赖
- linux 恢复误删除文件
- centos6.5下安装django
- TCP,Socket,HTTP,TCP和UDP的区别
- 网站开发常用技巧收集(防复制,防另存等等)
- 从Eclipse转移到IntelliJ IDEA一点心得
- Map去重,去重value相同的元素,保留key最小的那个值
- Html踩坑之旅
- android上传图片到服务器(使用base64字节流的形式通过 AsyncHttpClient框架传输)
- n阶乘后面0的个数
- HTML + CSS 块状元素 & 内联元素
- hdoj 1429 胜利大逃亡(续)< BFS + 状态压缩>
- 基于JADE的多Agent在Eclipse中搭建
- 转发与重定向
- JAVA 大数A+B
- 使用GridView以表格形式显示多张图片
- LeetCode 115、Distinct Subsequences
- leetcode-Remove Elements