Codeforces Round #FF (Div. 2) Problem B DZY Loves Strings
来源:互联网 发布:centos 不显示中文 编辑:程序博客网 时间:2024/05/22 01:51
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?
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.
Print a single integer — the largest possible value of the resulting string DZY could get.
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
In the test sample DZY can obtain "abcbbc", value = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41.
题意:有一个字符串s,由小写字母组成,它的价值为,w(s)是一个函数,输入给的,每个字母对应一个值。然后可以插入k个字符,求插入后的最大价值。
思路:贪心。先算出原字符串的价值,k个字符全插入在后面,就插函数值最大的那个字符。
#include <iostream>#include <stdio.h>#include <cmath>#include <algorithm>#include <iomanip>#include <cstdlib>#include <string>#include <memory.h>#include <vector>#include <queue>#include <stack>#include <ctype.h>#define INF 1000000000using namespace std;char str[1010];int k;//int tab[30];int main(){while(cin>>str){cin>>k;int maxf=0;for(int i=1;i<=26;i++){cin>>tab[i];if(tab[i]>maxf)maxf=tab[i];}int ans=0;for(int i=0;i<strlen(str);i++){ans+=(i+1)*tab[str[i]-96];}for(int i=strlen(str)+1;i<strlen(str)+1+k;i++){ans+=maxf*i;}cout<<ans<<endl;}return 0;}
- 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) 447B 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)/Codeforces447B_ DZY Loves Strings(字符串处理)
- Codeforces Round #FF (Div. 2) Problem A DZY Loves Hash
- Codeforces Round #FF (Div. 2):Problem A - DZY Loves Hash
- Codeforces Round #FF (Div. 2) Problem C DZY Loves Sequences
- Codeforces Round #FF (Div. 2) B.DYZ Loves Strings
- Codeforces Round #FF (Div. 1) B. DZY Loves Modification
- Codeforces Round #FF (Div. 2) A. DZY Loves Hash
- Codeforces Round #FF (Div. 2) A. DZY Loves Hash
- Codeforces Round #FF (Div. 2):C. DZY Loves Sequences
- Codeforces Round #FF (Div. 2)C - DZY Loves Sequences
- Codeforces Round #FF (Div. 2)-C. DZY Loves Sequences
- Codeforces Round #FF (Div. 2)C. DZY Loves Sequences
- Java实用小函数——(14年7月13)hibernate学习
- 各种demo——CI框架学习
- C++大学基础教程_12_面向对象编程:继承
- 沟通公式
- 黑马程序员--HTML 元素
- Codeforces Round #FF (Div. 2) Problem B DZY Loves Strings
- Android逆向工程工具Dare的使用方法(Mac OS X中)
- 指针的理解
- iPhone开发秘籍(第2版)--详细书签版
- 说过的话放假放假华国锋关键
- POJ2229 Sumsets 动态规划
- Mac系统完美配置Cocos2d-x 2.2.3 的Android+IOS双平台环境
- android 系统架构学习
- 2-1. 厘米换算英尺英寸(15)