日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

hdu 6034 B - Balala Power! 贪心

發(fā)布時(shí)間:2025/3/21 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 hdu 6034 B - Balala Power! 贪心 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

B - Balala Power!

題目鏈接

http://acm.hdu.edu.cn/showproblem.php?pid=6034

題面描述

Talented Mr.Tang has n strings consisting of only lower case characters. He wants to charge them with Balala Power (he could change each character ranged from a to z into each number ranged from 0 to 25, but each two different characters should not be changed into the same number) so that he could calculate the sum of these strings as integers in base 26 hilariously.

Mr.Tang wants you to maximize the summation. Notice that no string in this problem could have leading zeros except for string "0". It is guaranteed that at least one character does not appear at the beginning of any string.

The summation may be quite large, so you should output it in modulo 109+7.

輸入

The input contains multiple test cases.

For each test case, the first line contains one positive integers n, the number of strings. (1≤n≤100000)

Each of the next n lines contains a string si consisting of only lower case letters. (1≤|si|≤100000,∑|si|≤106)

輸出

For each test case, output "Case #x: y" in one line (without quotes), where x indicates the case number starting from 1 and y denotes the answer of corresponding case.

樣例輸入

1
a
2
aa
bb
3
a
ba
abc

樣例輸出

Case #1: 25
Case #2: 1323
Case #3: 18221

題意

給你n個(gè)由26個(gè)字母組成的字符串,你現(xiàn)在要給每個(gè)字母用[0,25]賦值,不能要求有前導(dǎo)0,每個(gè)值對應(yīng)一個(gè)字母.

要求使得字符串組成的數(shù)字和最大。

題解

直接算每個(gè)字母的貢獻(xiàn),然后賦值就行,把0給最小的合法的字母即可。

代碼

#include<bits/stdc++.h> using namespace std; const int maxn = 1e5+7; const int mod = 1e9+7; struct node{int len[maxn];int w;int v;int L; }p[26]; int n; string s[maxn]; int flag[26]; int cas = 0; bool cmp(node A,node B){if(A.L!=B.L)return A.L<B.L;for(int i=A.L;i>=0;i--){if(A.len[i]==B.len[i])continue;return A.len[i]<B.len[i];}return 0; } int main(){while(cin>>n){cas++;memset(flag,0,sizeof(flag));for(int i=0;i<26;i++){for(int j=0;j<=p[i].L;j++){p[i].len[j]=0;}}for(int i=0;i<26;i++){p[i].v=0;p[i].w=i;p[i].L=-1;}for(int i=0;i<n;i++){cin>>s[i];if(s[i].size()>1){flag[s[i][0]-'a']++;}reverse(s[i].begin(),s[i].end());for(int j=0;j<s[i].size();j++){p[s[i][j]-'a'].len[j]++;}}for(int i=0;i<26;i++){for(int j=0;j<maxn-1;j++){if(p[i].len[j]>=26){int d = p[i].len[j]/26;p[i].len[j]%=26;p[i].len[j+1]+=d;}if(p[i].len[j]>0){p[i].L=max(p[i].L,j);}}}sort(p,p+26,cmp);for(int i=0;i<26;i++){p[i].v=i;}for(int i=0;i<26;i++){if(flag[p[i].w]&&p[i].v==0){swap(p[i].v,p[i+1].v);}else break;}long long ans = 0;long long value[26];for(int i=0;i<26;i++){value[p[i].w]=p[i].v;}for(int i=0;i<n;i++){long long now = 1;for(int j=0;j<s[i].size();j++){ans=(ans+(value[s[i][j]-'a']*now)%mod)%mod;now=(now*26)%mod;}}cout<<"Case #"<<cas<<": "<<ans<<endl;} }

總結(jié)

以上是生活随笔為你收集整理的hdu 6034 B - Balala Power! 贪心的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。