2017杭电多校联赛-Balala Power!

Balala Power!

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


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.  (1n100000)

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
题目大意:给你一些字符串,这些字符串中的每一个字符都可以表示为0-25中的任何一个数字,但是不能有两个字符表示表示同一个数字,然后
要求得到最大的可能值。
解题思路:题目给你的字母,我们想要得到最大的和值,则需要将字母表示为尽可能大的数,在这里我们看到的这些字符串,实际上是26进制数,
所以我们可以先将这些26进制数转换为10进制,然后相加求和。具体看代码。
ac代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long 
const int N=105005;
const int mod=1000000007;
ll p[N];
int f[26],q[26],cnt[26][N]; 
char s[N];
int mysort(){
    int i,j,k;
    for(i=0;i<26;i++){
        for(j=i+1;j<26;j++){
            for(k=N-1;k>=0;k--){
                if(cnt[q[i]][k]<cnt[q[j]][k]){
                    int t=q[i];
                    q[i]=q[j];
                    q[j]=t;
                    break;
                }
                if(cnt[q[i]][k]>cnt[q[j]][k])
                    break;
            } 
        } 
    }
    if(f[q[25]]==1)
    {
        for(i=24;i>=0;i--){
            if(!f[q[i]]){
                for(j=i;j<25;j++)
                    q[j]=q[j+1];
                break;
            }
        }
    }
    
}
void init(){
    p[0]=1;
    for(int i=1;i<N;i++)
        p[i]=p[i-1]*26%mod;
}
int main(){
    ll ans;
    int i,j,n,m,x,t=1;
    init(); 
    while(~scanf("%d",&n)){ 
        memset(cnt,0,sizeof(cnt));
        memset(f,0,sizeof(f));
        for(i=0;i<26;i++)
            q[i]=i;
        for(i=0;i<n;i++){
            scanf("%s",s);
            m=strlen(s);
            for(j=0;j<m;j++){
                cnt[s[j]-'a'][m-j-1]++;
            }
            f[s[0]-'a']=1;
        }
        for(i=0;i<26;i++){
            for(j=0;j<N-1;j++){
                cnt[i][j+1]+=cnt[i][j]/26;
                cnt[i][j]%=26;    
            }
        }
        mysort();
        for(ans=i=0;i<25;i++){
            for(j=N-1;j>=0;j--)
            {
                if(cnt[q[i]][j]){
                    ans+=p[j]*cnt[q[i]][j]*(25-i),ans%=mod; 
                }
            }
        }
        printf("Case #%d: %lld\n",t++,ans);
    } 
    return 0;
}

题目链接: 点击打开链接http://acm.hdu.edu.cn/contests/contest_showproblem.php?cid=759&pid=1002

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值