您的位置:首页 > 其它

2017 多校训练第一场 HDU 6034 Balala Power!

2017-07-26 00:37 393 查看
#include <bits stdc="" h="">
// #define test TEST
using namespace std;
typedef long long ll;
const int maxn=100005;
const int mod=1e9+7;
string s[maxn];
char str[maxn],temp[maxn];
ll alpha[26],fac[maxn];
bool vis[26];
typedef struct Node{
int num[maxn];
int id;
}node;
node value[26];

bool cmp(const node &a,const node &b){
for(int i=100001;i>=0;i--){
if(a.num[i]!=b.num[i])
return a.num[i]>b.num[i];
}
return a.num[0]>b.num[0];
}

int main(int argc, char const *argv[])
{
#ifdef test
freopen("test.txt","r",stdin);
#endif
fac[0]=1;
for(int i=1;i<maxn;i++){
fac[i]=(fac[i-1]*26)%mod;
}
int cas=1,n;
while(~scanf("%d",&n)){
memset(vis,false,sizeof(vis));
memset(alpha,0,sizeof(alpha));
for(int i=0;i<26;i++){
memset(value[i].num,0,sizeof(value[i].num));
value[i].id=i;
}
int len=0;
for(int i=0;i<n;i++){
scanf("%s",str);
len=strlen(str);
for(int j=0;j<len;j++){
temp[len-1-j]=str[j];
}
if(len!=1) {
vis[str[0]-'a']=true;
}
for(int j=0;j<len j="" value="" temp="" j="" -="" a="" num="" j="" while="" value="" temp="" j="" -="" a="" num="" j="">=26){
value[temp[j]-'a'].num[j]-=26;
value[temp[j]-'a'].num[j+1]++;
}
}
}
sort(value,value+26,cmp);
int pos=-1;
for(int i=25;i>=0;i--){
if(!vis[value[i].id]){
pos=i;
break;
}
}
ll ans=0;
for(int i=0;i<26;i++){
if(i==pos) continue;
else if(i<pos ll="" cnt="25-i;" for="" int="" j="100001;j">=0;j--){
ans=(ans+(cnt*fac[j]*value[i].num[j]))%mod;
}
}
else{
ll cnt=25-i+1;
for(int j=100001;j>=0;j--){
ans=(ans+(cnt*fac[j]*value[i].num[j]))%mod;
}
}
}
printf("Case #%d: %lld\n",cas++,ans);
}
return 0;
}

</pos></len></bits>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: