Talented Mr.Tang has nn strings consisting of only lower case characters. He wants to charge them with Balala Power (he could change each character ranged from a to 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 2626 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+7109+7.


Input

  The input contains multiple test cases.

Output

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

  Each of the next nn lines contains a string sisi consisting of only lower case letters. (1≤|si|≤100000,∑|si|≤1e6)e
OutputFor each test case, output " Case #xx: yy" in one line (without quotes), where xxindicates the case number starting from 11 and yy denotes the answer of corresponding case.

Sample Input

1
a
2
aa
bb
3
a
ba
abc

Sample Output

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

题目大意:用26个字母表示26进制数中的1~26,并且给你n个字符串,以26进制从字符串转化为数字,问这些数字之和最大能有多少(以十进制输出)。为保证数据正确,其中必存在至少一个字母是代表了0。

思路:模拟。首先每个字母代表的数未知,但由于每个字符在字符串的位置是已知的,我们就可以求出每个字母从26进制转化十进制时的“系数”(即像26^a1+26^a2+26^a3……的数),用数组存储26进制数,在求和时考虑进位,去掉必为0的字母,然后对按26进制数的大小对数组排序,最后就能够求和解出答案了。。。比赛的时候是用的字符串存26进制,理论上也是可以做的,但是因为进位的姿势不对(一边加一边进位,先全部加完再进位才是正确的)导致TLE/(ㄒoㄒ)/

代码

 #include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<iomanip>
#include<cmath>
#define MOD 1000000007
#define MAXN 100010
using namespace std;
long long num[][MAXN],w[];
long long sum[];
long long a[MAXN];
int u;
char ss[MAXN];
bool vis[];
bool cmp(int s, int t)
{
for(int i=u-;i>=;i--){
if(num[s][i]!=num[t][i])
return num[s][i]<num[t][i];
}
return ;
}
int main()
{
a[]=;
for(int i=;i<MAXN-;i++)
a[i]=*a[i-]%MOD; int n;
int z=;
while(~scanf("%d", &n))
{
u=;
memset(num, , sizeof(num));
memset(sum, , sizeof(sum));
memset(vis,false,sizeof(vis));
int wei,p;
for(int i=;i<n;i++){
scanf("%s", ss);
int l=strlen(ss);
if(l>)
vis[ss[]-'a']=true; for(int j=;j<l;j++){
p=ss[j]-'a';
wei=l--j;
num[p][l--j]++;
sum[p]+=a[wei];
sum[p]%=MOD;
}
u=max(u, l);
}
for(int i=;i<;i++){
for(int j=;j<u;j++){
num[i][j+]=num[i][j+]+num[i][j]/;
num[i][j]=num[i][j]%;
}
while(num[i][u])
{
num[i][u+]+=num[i][u]/;
num[i][u++]%=;
u++;
}
w[i]=i;
}
int cnt=-;
sort(w, w+, cmp);
for(int i=;i<;i++){
if(!vis[w[i]]){
cnt=w[i];
break;
}
}
//cout<<cnt<<endl;
int res=,x=;
for(int i=;i>=;i--){
if(cnt!=w[i]){
res+=(long long)(x--)*sum[w[i]]%MOD;
res%=MOD;
} }
z=z+;
printf("Case #%d: %lld\n",z,res);
}
}

HDU 6034 Balala Power! —— Multi-University Training 1的更多相关文章

  1. HDU 6034 - Balala Power! | 2017 Multi-University Training Contest 1

    /* HDU 6034 - Balala Power! [ 大数进位,贪心 ] 题意: 给一组字符串(小写英文字母),将上面的字符串考虑成26进制数,每个字母分配一个权值,问这组数字加起来的和最大是多 ...

  2. 2017 Multi-University Training Contest - Team 1 1002&&HDU 6034 Balala Power!【字符串,贪心+排序】

    Balala Power! Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  3. HDU 6034 Balala Power!(贪心+排序)

    Balala Power! Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  4. hdu 6034 Balala Power!

    Balala Power! Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  5. 2017ACM暑期多校联合训练 - Team 1 1002 HDU 6034 Balala Power! (字符串处理)

    题目链接 Problem Description Talented Mr.Tang has n strings consisting of only lower case characters. He ...

  6. HDU 6034 Balala Power!【排序/进制思维】

    Balala Power![排序/进制思维] Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java ...

  7. HDU 6034 Balala Power! (贪心+坑题)

    题意:给定一个 n 个字符串,然后问你怎么给 a-z赋值0-25,使得给定的字符串看成26进制得到的和最大,并且不能出现前导0. 析:一个很恶心的题目,细节有点多,首先是思路,给定个字符一个权值,然后 ...

  8. 6034 Balala Power! (17多校)

    题目大意:给出的字符串,每个字符建立一种与0-25的对应关系.然后每个字符串看成是一个26进制的数.问能获得的数的总和的最大值.(最后对1e9+7取模). 题目思考:把每个字符的贡献值看做一个26进制 ...

  9. hdu 6034 B - Balala Power! 贪心

    B - Balala Power! 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=6034 题面描述 Talented Mr.Tang has n st ...

随机推荐

  1. 获取小程序accessToken

    private static String getAccessToken(){ String url = "https://api.weixin.qq.com/cgi-bin/token? ...

  2. 测开之路八十三:高级函数:map()和filter()

    # map(函数名,可迭代对象)# 给可迭代对象的每个值+5l = list(range(1, 21)) def add_number(x):    return x + 5 # 第一种方式print ...

  3. windows10上使用一个tomcat部署2个项目

    前言:目前想在本机部署2个项目,网上查了之后,写下本篇随笔 1.准备工作 2.操作方法 3.运行2个项目 1.准备工作 2个war包(一个jprss.war和一个jenkins.war) 1个tomc ...

  4. 传统神经网络ANN训练算法总结 参考 。 以后研究

    http://blog.163.com/yuyang_tech/blog/static/21605008320146451352506/ 传统神经网络ANN训练算法总结 2014-07-04 17:1 ...

  5. PTA 1154 Vertex Coloring

    题目链接:1154 Vertex Coloring A proper vertex coloring is a labeling of the graph's vertices with colors ...

  6. 深信达加密下禁用IME

    1.控制面板 2.管理工具 3.计算机管理 4.系统工具 5.任务计划程序 6.任务计划程序库 7.Microsoft 8.Windows 9.TextServicesFramework 10.MsC ...

  7. maven基础--下载安装配置命令生命周期

    maven apache 公司开源项目,项目构建工具 好处: 项目小 坐标:公司名称+项目名称+版本信息 通过坐标去 仓库查找jar包 maven的两大核心: *赖管理:对jar包管理过程. 项目构建 ...

  8. vue构造器注册UI组件

    import ConfirmComponent from '../../components/confirm/index' import { mergeOptions } from '../plugi ...

  9. express框架中router组件的app.use和app.get

    首先看例子: var express = require('express'); var router = express.Router(); var index = require('./route ...

  10. 【洛谷p1464】 Function

    中考第一天: 感觉我超废: 就是看这道题特别顺眼emmm SOLUTION: 思路的话是开三维数组s[i][j][k],先三重for循环预处理出s[0~20][0~20][0~20]的w(a,b,c) ...