Balala Power!

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 3757    Accepted Submission(s): 907

Problem Description

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.

 
Input
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)

 
Output
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.
 
Sample Input
1
a
2
aa
bb
3
a
ba
abc
 
Sample Output
Case #1: 25
Case #2: 1323
Case #3: 18221
 
Source
 题意:
a~z每个字符代表着0~25中的个一个数字,因此一个字符串就可以表示成一个26进制的数字,给出n个字符串求这n个字符串和的最大值。
输入n
输入n行字符串
代码:
//进位和去前导零!!!;统计每个字符在某一位置出现的次数(共1e5个位置),然后贪心一定是贡献值最大的
//用25,把统计出来的数组按照高位出现次数大的排序(可以按照数组排序),然后算就行了。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod=1e9+;
const int maxl=;
int pre[];
ll f[maxl];
struct Lu{
int id,ss[maxl];
ll v;
bool operator < (const Lu &p)const{
for(int i=maxl-;i>=;i--){
if(ss[i]>p.ss[i]) return ;
else if(ss[i]<p.ss[i]) return ;
}
}
}L[];
void init(){
f[]=;
for(int i=;i<maxl;i++){
f[i]=f[i-]*%mod;
}
}
int main()
{
init();
int cas=,n;
char str[maxl];
while(scanf("%d",&n)==){
memset(pre,,sizeof(pre));
memset(L,,sizeof(L));
for(int i=;i<n;i++){
scanf("%s",str);
int len=strlen(str)-;
if(len!=)
pre[str[]-'a']=;
for(int j=len;j>=;j--){
int id=str[j]-'a';
L[id].ss[len-j]++;
}
}
for(int i=;i<;i++){
L[i].id=i;
for(int j=;j<maxl-;j++){
if(L[i].ss[j]>=){
L[i].ss[j+]+=L[i].ss[j]/;
L[i].ss[j]%=;
}
}
}
sort(L,L+);
for(int i=;i<;i++)
L[i].v=-i;
if(pre[L[].id]){ //去前导零时可不是直接交换
for(int i=;i>=;i--){
if(!pre[L[i].id]){
for(int j=;j>i;j--)
L[j].v=L[j-].v;
L[i].v=;
break;
}
}
}
ll sum=;
for(int i=;i<;i++){
for(int j=maxl-;j>=;j--){
sum+=L[i].v*f[j]*L[i].ss[j]%mod;
sum%=mod;
}
}
printf("Case #%d: %lld\n",++cas,sum);
}
return ;
}

最新文章

  1. 动画系统(Mecanim补充)
  2. 工厂食堂3D指纹考勤系统解决方案
  3. 【原创】Matlab.NET混合编程技巧之找出Matlab内置函数
  4. 二、Sink例程
  5. [C/CPP系列知识] 在C中使用没有声明的函数时将发生什么 What happens when a function is called before its declaration in C
  6. effective c++(04)之对象使用前初始化
  7. oracle AWR深入研究分析,如何使用
  8. 【转】Service Intent must be explicit的解决方法
  9. Jni Tips
  10. spark-2.2.0安装和部署——Spark集群学习日记
  11. Android - include属性用法
  12. 关于获取URL中传值的解决方法--升级版
  13. 机器学习入门11 - 逻辑回归 (Logistic Regression)
  14. document.ready(function(){}),window.onload,$(function(){})的区别
  15. [快速幂][NOIP2012]转圈游戏
  16. systemd开机启动
  17. hdu 3068
  18. Linux入门进阶第六天——登录文件、开机与模块管理
  19. makefile使用笔记(二)变量
  20. HTML系列(1)简介

热门文章

  1. 从零开始的Python学习Episode 11——装饰器
  2. Maven私有仓库搭建以及使用
  3. Alpha事后诸葛会议
  4. lintcode-206-区间求和 I
  5. PHP初级
  6. AdminLTE 框架应用(一 )- 插件介绍
  7. p2 钢体
  8. SQL 抛出异常的例子 RAISERROR 的使用
  9. MVC中ajax提交表单示例
  10. 【Python】第一篇:python基础_1