码迷,mamicode.com
首页 > 其他好文 > 详细

[2016-04-13][codeforces][447][B][DZY Loves Strings]

时间:2016-04-14 01:21:05      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:

  • 时间:2016-04-13 23:36:46 星期三

  • 题目编号:[2016-04-13][codeforces][447][B][DZY Loves Strings]

  • 题目大意:已知每个字母的权值,给定一个字符串s,问,插入k个字母进入字符串s之和,最多能得到多大的权值

  • 分析:直接往s后面插入k个权值最大的字母

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. using namespace std;
  5. char str[1000 + 10];
  6. int w[27];
  7. int main(){
  8. long long ans = 0;int wmax = 0,k;
  9. scanf("%s%d",str,&k);
  10. int len = strlen(str);
  11. for(int i = 0 ; i < 26 ; ++i){
  12. scanf("%d",w+i);
  13. wmax = max(wmax,w[i]);
  14. }
  15. for(int i = 0 ;i < len ; ++i){
  16. ans += (long long )(i+1) * w[str[i] - ‘a‘];
  17. }
  18. ans += (long long )wmax*(len + 1 + len + k)*k/2;
  19. printf("%I64d\n",ans);
  20. return 0;
  21. }




[2016-04-13][codeforces][447][B][DZY Loves Strings]

标签:

原文地址:http://www.cnblogs.com/qhy285571052/p/17f57f6d415f4a96328dad2d8e5d84f9.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!