HDU 6043 (2017 多校训练赛1 1002) Balala Power!


 2017 Multi-University Training Contest - Team 1 1002

Balala Power!



Problem Description
HDU 6043 (2017 多校训练赛1 1002) Balala Power!_第1张图片

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 #xy" 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
 

   

    题意:给出 n个字符串,字符包括 a~z,分别给它们赋值 0~25,使得这些串表达成26进制时的和最大

    分析:模拟一个26进制的数组p[10010][26] 分别表示每一位每个字母有多少个,当超过26的时候就向前进位
那么可以得到每个字母的权值,将它们的权值从大到小排序,然后赋值
这时候要考虑一个前导0的问题,所以在录入的时候要先标记好哪些字母不能为0
然后将字母按赋值从大到小排序,从小的扫过去,找到第一个可以被赋值为0的,其他的向左推一位

最后将值带入计算就可以了

补充一下坑点:
1 前导0的判断
2 数组要开大一点,计算的时候也要预留几位,因为在进位的时候会超过最大的len(类似于高精度加法)


AC代码:

#include
#include
#include
#define mod 1000000007
using namespace std;
long long num[30];
long long p[100015][30];
long long vis[30];
long long re[100015];
int viss[30];
struct tree
{
    long long t;
    int v;
}Q[30];
struct stree
{
    char anss[100015];
    int v;
}P[30];
bool com(tree a,tree b)
{
    return a.tb.t;
}
bool comq(stree a,stree b)
{
    for(int i=0;i<100015;i++)
    {
        if(a.anss[i]>b.anss[i])
        return 0;
        else if(a.anss[i]=26)
                {
                    p[j+1][a[k]-'a']+=p[j][a[k]-'a']/26;
                    p[j][a[k]-'a']=p[j][a[k]-'a']%26;
                }
                if(lenn>1&&j==lenn-1)
                vis[a[k]-'a']=1;
            }
            len=max(len,lenn);
        }
        for(int i=0;i=26)
                {
                    p[i+1][j]+=p[i][j]/26;
                    p[i][j]=p[i][j]%26;
                }
            }
        }
        for(int k=0;k<26;k++)
        {
            for(int i=len+10,j=0;i>=0;i--,j++)
            {
                P[k].anss[j]=p[i][k]+'a';
            }
            P[k].v=k;
        }
        sort(P,P+26,comq);
        for(int i=0;i<26;i++)
        {
            if(viss[P[i].v])
            num[P[i].v]=i;
        }
        for(int i=0;i<26;i++)
        {
            Q[i].t=num[i];
            Q[i].v=i;
        }
        sort(Q,Q+26,com);
        for(int i=0;i<26;i++)
        {
            if(vis[Q[i].v])
            num[Q[i].v]++;
            else
            {
                num[Q[i].v]=0;
                break;
            }
        }
        long long ans=0;
        for(int i=0;i



你可能感兴趣的:(贪心专题,多校训练赛)