CF 447B(DZY Loves Strings-贪心)
1 second
256 megabytes
standard input
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?
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.
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
41
In the test sample DZY can obtain "abcbbc", value = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41.
贪心,不难想到取最大的w扔在末尾
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define MAXN (1000+10)
long long mul(long long a,long long b){return (a*b)%F;}
long long add(long long a,long long b){return (a+b)%F;}
long long sub(long long a,long long b){return (a-b+(a-b)/F*F+F)%F;}
typedef long long ll;
char s[MAXN];
int k,w[MAXN];
int main()
{
// freopen("Strings.in","r",stdin);
// freopen(".out","w",stdout); scanf("%s\n%d",s+1,&k); int len=strlen(s+1); int p=0;
Fork(i,'a','z') cin>>w[i],p=max(p,w[i]); ll ans=0;
For(i,len) ans+=w[s[i]]*i; if (k) ans+=(len+1+len+k)*k/2*p; cout<<ans<<endl; return 0;
}
CF 447B(DZY Loves Strings-贪心)的更多相关文章
- CF447B DZY Loves Strings 贪心
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter ...
- [CodeForces - 447B] B - DZY Loves Strings
B - DZY Loves Strings DZY loves collecting special strings which only contain lowercase letters. For ...
- Codeforces Round #254 (Div. 1) D - DZY Loves Strings
D - DZY Loves Strings 思路:感觉这种把询问按大小分成两类解决的问题都很不好想.. https://codeforces.com/blog/entry/12959 题解说得很清楚啦 ...
- Codeforces Round #254 (Div. 1) D. DZY Loves Strings hash 暴力
D. DZY Loves Strings 题目连接: http://codeforces.com/contest/444/problem/D Description DZY loves strings ...
- Codeforces Round #FF (Div. 2):B. DZY Loves Strings
B. DZY Loves Strings time limit per test 1 second memory limit per test 256 megabytes input standard ...
- CF 444C DZY Loves Physics(图论结论题)
题目链接: 传送门 DZY Loves Chemistry time limit per test1 second memory limit per test256 megabytes Des ...
- CF 445B DZY Loves Chemistry(并查集)
题目链接: 传送门 DZY Loves Chemistry time limit per test:1 second memory limit per test:256 megabytes D ...
- CF 444A(DZY Loves Physics-低密度脂蛋白诱导子图)
A. DZY Loves Physics time limit per test 1 second memory limit per test 256 megabytes input standard ...
- CF 444B(DZY Loves FFT-时间复杂度)
B. DZY Loves FFT time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
随机推荐
- validate命令---rman进行备份和回复的验证
rman作为oracle备份与恢复工具,为我们提供了强大的功能.当中包含对数据文件的物理和逻辑检測以及备份文件的有效性检測. 首先.来看一下rman对数据文件的检測. 我们知道,rman在备份数据时, ...
- IOS-2-C语言和Objective-C语言衔接学习资料
前言:在IOS学习中.通常会先学习一周的C语言,两周的Objective-C语言,这是今后开发的最基础最重要的部分,以下给大家分享一下培训课上的精简资料: C语言和Objective-C语言衔接学习资 ...
- 自醒的觉悟与力量——leo鉴书59
30岁之后由于看得书多起来,阅读和写作也都有了自己的套路,与此相对的写书评之前须要看几遍书,然后我才干下笔的作者和作品越来越少了. 崔卫平是这种作者,而<正义之前>是我看了两遍才開始写评的 ...
- Caffe C++API 提取任意一张图片的特征系列二----MemoryData
介绍一种更加灵活的方法,用MemoryData层输入数据,可以直接用opencv接口读入我们的图片再添加的网络中. 第一个问题:仍然是工程建立问题,提示卷积层或其他层没有注册,解决方法与上一篇博客一 ...
- CentOS 7 安装 vmware tools 提示The path "" is not a valid path to the 3.10.0-957.el7.x86_64 kernel headers.
输入“mkdir /mnt/cdrom”在/mnt目录下新建一个名为cdrom的文件夹 mkdir /mnt/cdrom 输入“mount -t iso9660 /dev/cdrom /mnt/cdr ...
- roboware-studio 使用教程
一.创建工作区 1.1 新建工作区 1.2 选择路径并添加工作区的名字 catkin_ws 二.创建程序包 创建ROS包并添加依赖 my_package roscpp std_msgs 三.添加并编写 ...
- Spark RDD概念学习系列之Pair RDD的action操作
不多说,直接上干货! Pair RDD的action操作 所有基础RDD 支持的行动操作也都在pair RDD 上可用
- jQuery分页插件pagination的用法
https://www.zhangxinxu.com/jq/pagination_zh/ 参数: 参数名 描述 参数值 maxentries 总条目数 必选参数,整数 items_per_page 每 ...
- GreenDao 3.X之基本使用
在GreenDao 3.X之注解已经了解到GreenDao 3.0的改动及注解.对于数据库的操作,无异于增删改查等四个操作.下面我们将了解GreenDao 3.X如何使用? AbstractDao 所 ...
- Hibernate框架学习(三)——实体规则、对象状态、一级缓存
一.Hibernate中的实体规则 1.实体类创建的注意事项 1)持久化类提供无参数构造,因为在Hibernate的底层需要使用反射生成类的实例. 2)成员变量私有,提供公有的get和set方法,需提 ...