CodeForces - 447B DZY Loves Strings

1000分也挺水…我写的简洁又好看

看着1300挺难,还有dp…行吧,不管感觉水不水就稳定1300了。

#include 
#include 
#include 
#include 

using namespace std;


char ch[1020];
int w[27], k;

int main(){

    scanf("%s",ch);
    int len = strlen(ch);

    cin >> k;

    int maxn = -1;
    for(int i = 0; i < 26; ++i){
        cin >> w[i];
        maxn = max(maxn, w[i]);
    }

    int res = 0;

    for(int i = 0, j= 1; ch[i]; ++i,++j)
        res += j*w[ch[i]-'a'];
    while(k--)
        res += ++len*maxn;

    cout << res << endl;

    return 0;
}

你可能感兴趣的:(Codeforces,贪心)