447B. DZY Loves Strings
来源:互联网 发布:雕刻机钻孔编程视频 编辑:程序博客网 时间:2024/05/16 09:56
B. DZY Loves Strings
time limit per test
1 secondmemory limit per test
256 megabytesinput
standard inputoutput
standard outputDZY loves collecting special strings which only contain lowercase letters. For each lowercase letterc DZY knows its value wc. For each special strings = s1s2...s|s| (|s| is the length of the string) he represents its value with a functionf(s), where
题意分析:插入字符,要求Fn最大,只需要插入k个权值最大的字符即可。
Now DZY has a string s. He wants to insertk 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 towz. Each such number is non-negative and doesn't exceed1000.
Output
Print a single integer — the largest possible value of the resulting string DZY could get.
Examples
Input
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
Output
41
Note
In the test sample DZY can obtain "abcbbc",value = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41.
题意分析:插入字符,要求Fn最大,只需要插入k个权值最大的字符即可。
#include <stdio.h>#include <bits/stdc++.h>using namespace std;#define ll long longint main() { string s; int k; cin >> s >> k; int w[26],res=0,max=0; for(int i=0;i<26;i++){ cin >> w[i]; if(max<w[i]) max = w[i]; } for(int i=0;i<s.length();i++){ res += w[(s[i]-97)]*(i+1); } for(int i=s.length()+1;i<=s.length()+k;i++){ res += max*i; } cout << res << endl; return 0; }
阅读全文
0 0
- 447B. DZY Loves Strings
- B. DZY Loves Strings
- B. DZY Loves Strings
- Codeforces 447B DZY Loves Strings
- CF 447B(DZY Loves Strings-贪心)
- codeforces-447B-DZY Loves Strings
- CodeForces 447B---DZY Loves Strings
- CodeForces 447B DZY Loves Strings
- CodeForces 447B DZY Loves Strings
- Codeforces 447B DZY Loves Strings
- CF 447B DZY Loves Strings(水题)
- Codeforces Round #FF (Div. 2) 447B DZY Loves Strings
- DZY Loves Strings
- Codeforces Round #FF (Div. 2) Problem B DZY Loves Strings
- Codeforces Round #FF (Div. 2):B. DZY Loves Strings
- Codeforces Round #FF (Div. 2) B. DZY Loves Strings
- Codeforces Round #FF (Div. 2)B. DZY Loves Strings
- Codeforces Round #FF (Div. 2)B. DZY Loves Strings
- 文件“obj\Debug\android\bin\packaged_resources”不存在
- 数据
- nodeJS中读写文件方法的区别
- ios-NSURLSession注意点
- 设计模式
- 447B. DZY Loves Strings
- (人脸识别2-7)——利用分类器识别本人
- ScrollView,ListView,ViewPage滑动到底的阴影,overScrollMode的使用
- poj 2186 强连通缩点求出度为0点是否唯一
- Linux学习 CDN加速
- Coursera机器学习 Week6 笔记
- 盒模型
- Palindromic Substrings问题及解法
- win10 下利用eclise 访问本地的hadoop 和 虚拟机下的hadoop