codeforces-447B-DZY Loves Strings

简介:
DZY Loves Strings
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
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 test(s)
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
Note
In the test sample DZY can obtain "abcbbc", value=1·1+2·2+3·2+4·2+5·2+6·2=41.






练练codeforces的评测
简单的字符串处理

AC代码:

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char s[2000];
int a[30];
int main()
{
    int i,m,n,sum=0,max;
    scanf("%s %d",s,&n);
    for(i=0;i<26;i++)
    scanf("%d",&a[i]);
    m=strlen(s);
    for(i=0;i<m;i++)
    sum+=(i+1)*a[s[i]-'a'];
    max=*max_element(a,a+26);
    i=m+1;
    while(n--)
    {
       sum+=i*max;
       i++;
    }
    printf("%d\n",sum);
    return 0;
}

相关文章
|
6月前
|
人工智能
HDU-1159-Common Subsequence
HDU-1159-Common Subsequence
33 0
|
6月前
poj-1458-Common Subsequence
poj-1458-Common Subsequence
30 0
|
6月前
|
Java
HDU-1865-1sting
HDU-1865-1sting
33 0
|
12月前
|
机器学习/深度学习
hdu 1061 Rightmost Digit
hdu 1061 Rightmost Digit
28 0
|
算法
POJ3061 Subsequence
POJ3061 Subsequence
UVa10776 - Determine The Combination(有重复元素的组合问题)
UVa10776 - Determine The Combination(有重复元素的组合问题)
43 0
|
索引
LeetCode 392. Is Subsequence
给定字符串 s 和 t ,判断 s 是否为 t 的子序列。 你可以认为 s 和 t 中仅包含英文小写字母。字符串 t 可能会很长(长度 ~= 500,000),而 s 是个短字符串(长度 <=100)。 字符串的一个子序列是原始字符串删除一些(也可以不删除)字符而不改变剩余字符相对位置形成的新字符串。(例如,"ace"是"abcde"的一个子序列,而"aec"不是)。
101 0
LeetCode 392. Is Subsequence
LeetCode 376. Wiggle Subsequence
如果连续数字之间的差严格地在正数和负数之间交替,则数字序列称为摆动序列。第一个差(如果存在的话)可能是正数或负数。少于两个元素的序列也是摆动序列。
93 0
LeetCode 376. Wiggle Subsequence
CodeForces 1195C Basketball Exercise (线性DP)
CodeForces 1195C Basketball Exercise (线性DP)
119 0
POJ-1458,Common Subsequence(经典DP)
POJ-1458,Common Subsequence(经典DP)