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 ...
随机推荐
- 每一个程序猿都须要了解的一个SQL技巧
对于数据过滤而言CHECK约束已经算是相当不错了.然而它仍存在一些缺陷,比方说它们是应用到表上面的,但有的时候你可能希望指定一条约束,而它仅仅在特定条件下才生效. 使用SQL标准的WITH CHECK ...
- POJ 2299 离散化线段树
点击打开链接 Ultra-QuickSort Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 40827 Accepted ...
- HttpClient学习系列 -- 学习总结
jar包: HttpClient 4.x版本 简要介绍 HttpComponents 包括 HttpCore包和HttpClient包 HttpClient:Http的执行http请求 Default ...
- BZOJ 3160: 万径人踪灭 FFT+快速幂+manacher
BZOJ 3160: 万径人踪灭 题目传送门 [题目大意] 给定一个长度为n的01串,求有多少个回文子序列? 回文子序列是指从原串中找出任意个,使得构成一个回文串,并且位置也是沿某一对称轴对称. 假如 ...
- Swift - 制作一个在线流媒体音乐播放器(使用StreamingKit库)
在之前的文章中,我介绍了如何使用 AVPlayer 制作一个简单的音乐播放器(点击查看1.点击查看2).虽然这个播放器也可以播放网络音频,但其实际上是将音频文件下载到本地后再播放的. 本文演示如何使用 ...
- java.lang.NoClassDefFoundError: javax/servlet/ServletInputStream
转自:https://blog.csdn.net/y970105/article/details/355401 进入 tomcat根目录/lib/servlet-api.jar复制出来,放到JDK_P ...
- 6.vi使用
- week3_notebooke1
今日内容:编码集合深浅cpoy文件操作函数初始函数函数的返回值函数的传参 初识: # == 数值比较 # is 比较的是内存地址 # id 测试的是内存地址 # 小数据池 str int # int: ...
- Repeater控件使用小结持续更新
Repeater嵌套Repeater绑定数据 前台代码 <!--注意层级关系不要写错了--> <asp:Repeater ID="rpGroup" runat=& ...
- BZOJ4819: [Sdoi2017]新生舞会(01分数规划)
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1029 Solved: 528[Submit][Status][Discuss] Descripti ...