• Codeforces Round #FF (Div. 2):B. DZY Loves Strings


    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard 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


    题意:输入子串, 大小相应以下你输入的26个字母的大小, 后面再输入一个数字K,即你加入的过少个字母,要想结果最大。。就要找出你输入的26个字母相应数值大小最大的字母。。

    就像案列中的B和C是最大的, 所以就加入其。



    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #include<vector>
    #include<queue>
    #include<sstream>
    #include<cmath>
    
    using namespace std;
    
    #define f1(i, n) for(int i=0; i<n; i++)
    #define f2(i, m) for(int i=1; i<=m; i++)
    #define f3(i, n) for(int i=n; i>=0; i--)
    #define M 1005
    
    const int INF = 0x3f3f3f3f;
    
    int main()
    {
        char s[1005];
        int a, b, i, t=-1;
        __int64 d=0;
        int eng[27], c[1005];
        scanf("%s", s);
        b=strlen(s);
        scanf("%d", &a);
        for(i=1; i<=26; i++)
        {
            scanf("%d",&eng[i]);
            if( t<eng[i] )
                t = eng[i];
        }
        for(i=0; i<b; i++)
        {
            c[i] = s[i]-'a'+1;
            d = d + eng[c[i]]*(i+1);
        }
        for(i=1; i<=a; i++)
            d = d + t*(b+i);
        printf("%I64d
    ",d);
        return 0;
    }
    



  • 相关阅读:
    StarUML中时序图
    HTML5/jQuery雷达动画图表 图表配置十分简单
    AspNetPager样式以及属性帮助文档
    IE浏览器img不显示解决
    php表单提交--文件
    javascript继承---组合式继承
    javascript继承--原型链的 继承
    【转】JavaScript 之arguments、caller 和 callee 介绍
    Array对象
    android 系统提示对话框(AlertDialog)的使用
  • 原文地址:https://www.cnblogs.com/lytwajue/p/6993420.html
Copyright © 2020-2023  润新知