您的位置:首页
CF 447B(DZY Loves Strings-贪心)
2017-06-23 21:05
369 查看
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
![](http://img.blog.csdn.net/20140714202654954)
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
output
Note
In the test sample DZY can obtain "abcbbc", value = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41.
贪心,不难想到取最大的w扔在末尾
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.
贪心,不难想到取最大的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-贪心)
- CF D. DZY Loves Strings(字符串hash 暴力)
- CodeForces 447B---DZY Loves Strings
- codeforces-447B-DZY Loves Strings
- CF 444C DZY Loves Colors
- 【HDU5646 BestCoder Round 76 (div1)A】【贪心】DZY Loves Partition n个数拆分k个最大乘积
- Codeforces Round #FF (Div. 2) B. DZY Loves Strings
- CF 255 DIV2 D DZY Loves Modification(优先队列)
- B. DZY Loves Strings
- ARC#058F Iroha Loves Strings(贪心+字符串处理+dp预处理)
- 【HDU】5195-DZY Loves Topological Sorting(拓扑 + 线段树 + 贪心)
- CF Round #FF (Div. 2) C DZY Loves Sequences_DP
- hdu.5195.DZY Loves Topological Sorting(topo排序 && 贪心)
- Codeforces Round #FF (Div. 2):B. DZY Loves Strings
- Codeforces Round #FF (Div. 2):B. DZY Loves Strings
- Codeforces Round #FF (Div. 2) D. DZY Loves Modification 贪心+优先队列
- CF 444B(DZY Loves FFT-时间复杂度)
- Codeforces Round #FF (Div. 2/B)/Codeforces447B_ DZY Loves Strings(字符串处理)
- CF FF# E .DZY Loves Fibonacci Numbers
- codeforces 444D DZY Loves Strings