/*hdu6034[模拟] 2017多校1*/
//暴力模拟26个26进制数即可, 要注意进位
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const double eps=1e-;
const int inf=0x3f3f3f3f;
struct node{
char num[];
int ch,high;
}bits[];
const int mod=;
int n,len,pos,mark[],w[],kase=;
char str[];
LL fastpow(LL a,LL b){
LL ret=,x=a;
while(b){
if(b&){
ret=(ret*x)%mod;
}
x=(x*x)%mod;
b>>=;
}
return ret;
}
bool cmp(node a,node b){
if(a.high!=b.high){
return a.high>b.high;
}
else{
for(int i=a.high-;i>=;i--){
if(a.num[i]>b.num[i]){
return ;
}
else if(a.num[i]<b.num[i]){
return ;
}
}
}
return ;
}
LL cal(node& a){
LL ret=;
for(int i=;i<a.high;i++){
if(a.num[i]){
ret=(ret+((LL)a.num[i]*fastpow(26LL,i))%mod)%mod;
}
}
return ret;
}
void solve(){
LL sum=;
sort(bits,bits+,cmp);
for(int i=;i<;i++){
if(bits[i].high) w[bits[i].ch]=-i;
if(mark[bits[i].ch]&&w[bits[i].ch]==){
int pos=i;
while(mark[bits[pos].ch]&&pos) pos--;
for(int j=pos+;j<;j++) w[bits[j].ch]++;
w[bits[pos].ch]=;
}
}
for(int i=;i<;i++){
sum=(sum+w[bits[i].ch]*cal(bits[i]))%mod;
}
printf("Case #%d: %lld\n",kase++,sum);
}
int main(){
while(~scanf("%d",&n)){
memset(bits,,sizeof(bits));
memset(w,,sizeof(w));
memset(mark,,sizeof(mark));
for(int i=;i<;i++) bits[i].ch=i;
for(int i=;i<n;i++){
scanf("%s",str);
len=strlen(str);
mark[str[]-'a']++;
for(int i=;i<len;i++){
pos=len-i-;
bits[str[i]-'a'].high=max(bits[str[i]-'a'].high,pos+);
bits[str[i]-'a'].num[pos]++;
while(pos<&&bits[str[i]-'a'].num[pos]>=){
int k=bits[str[i]-'a'].num[pos]/;
bits[str[i]-'a'].num[pos]-=;
bits[str[i]-'a'].num[++pos]++;
}bits[str[i]-'a'].high=max(bits[str[i]-'a'].high,pos+);
}
}solve();
}
return ;
}

hdu6034[模拟] 2017多校1的更多相关文章

  1. hdu6136[模拟+优先队列] 2017多校8

    有点麻烦.. /*hdu6136[模拟+优先队列] 2017多校8*/ #include <bits/stdc++.h> using namespace std; typedef long ...

  2. 2017 多校5 hdu 6093 Rikka with Number

    2017 多校5 Rikka with Number(数学 + 数位dp) 题意: 统计\([L,R]\)内 有多少数字 满足在某个\(d(d>=2)\)进制下是\(d\)的全排列的 \(1 & ...

  3. 2017 多校5 Rikka with String

    2017 多校5 Rikka with String(ac自动机+dp) 题意: Yuta has \(n\) \(01\) strings \(s_i\), and he wants to know ...

  4. 2017 多校4 Wavel Sequence

    2017 多校4 Wavel Sequence 题意: Formally, he defines a sequence \(a_1,a_2,...,a_n\) as ''wavel'' if and ...

  5. 2017 多校4 Security Check

    2017 多校4 Security Check 题意: 有\(A_i\)和\(B_i\)两个长度为\(n\)的队列过安检,当\(|A_i-B_j|>K\)的时候, \(A_i和B_j\)是可以同 ...

  6. 2017 多校3 hdu 6061 RXD and functions

    2017 多校3 hdu 6061 RXD and functions(FFT) 题意: 给一个函数\(f(x)=\sum_{i=0}^{n}c_i \cdot x^{i}\) 求\(g(x) = f ...

  7. 2017 多校2 hdu 6053 TrickGCD

    2017 多校2 hdu 6053 TrickGCD 题目: You are given an array \(A\) , and Zhu wants to know there are how ma ...

  8. 2017 多校1 I Curse Myself

    2017 多校2 I Curse Myself(第k小生成树) 题目: 给一张带权无向连通图,该图的任意一条边最多只会经过一个简单环,定义\(V(k)为第k小生成树的权值和\),求出\(\sum_{k ...

  9. hdu6134[莫比乌斯反演] 2017多校8

    /*hdu6134[莫比乌斯反演] 2017多校8*/ #include <bits/stdc++.h> using namespace std; typedef long long LL ...

随机推荐

  1. userBean-作用范围session

    package com.java1234.model; public class Student { private String name;private int age; public Strin ...

  2. 随记:UWP开发中怎么使当前页面拓展到标题栏

    public sealed partial class MainPage : Page { public MainPage() { this.InitializeComponent(); CoreAp ...

  3. python爬虫之路——变量和变量类型

    变量类型: ①单值:int ②多值:数组 ③复杂:类 变量类型:就是变量的数据结构,表示这个变量所代表的内容的格式是怎样的. (多值)四种基本数据结构: 列表,字典,元组,集合 列表: ①元素可变,  ...

  4. Codeforces 464E #265 (Div. 1) E. The Classic Problem 主席树+Hash

    E. The Classic Problem http://codeforces.com/problemset/problem/464/E 题意:给你一张无向带权图,求S-T的最短路,并输出路径.边权 ...

  5. 如何处理VirtualBox启动错误消息:The vboxdrv kernel module is not loaded

    我在启动minikube时,遇到如下错误消息: Starting local Kubernetes v1.10.0 cluster... Starting VM... E1010 03:27:37.9 ...

  6. 弄了一个星期的wp 8.1,吐血的感觉

    看到8.1出来这么久了,心痒难耐,忍不住想重新把应用写一遍,于是上个星期开始动手,用的mvvm模式,结果一路下来,sqlce不能用了,那好吧,我用sqlite,webrequest变成httpclie ...

  7. UVA 11627 Slalom(二分)

    二分,判断的时候,一个点一个点的考虑肯定是不行啦,考虑的单位是一个区间, 每次左端点尽量向左边移动,右端点尽量向右,得到下次可以达到的范围,检查一下和下一个区间有没有交集. #include<b ...

  8. iOS中的数据存储方式_SQLite3

    优点: 1) SQLite是一款轻型的嵌入式数据库; 2) 它占用资源非常的低,在嵌入式设备中,可能只需要几百K的内存就够了 3) 它的处理速度比Mysql.PostgreSQL这两款著名的数据库都还 ...

  9. django logging日志优先级

    原创博文 转载请注明出处! 参考官方文档:https://docs.djangoproject.com/en/2.1/topics/logging/ Loggers¶ A logger is the ...

  10. http 基础与通讯原理

    目录 http 基础与通讯原理 Internet 与中国 1990年10月 注册CN顶级域名 1993年3月2日 接入第一根专线 1994年4月20日 实现与互联网的全功能连接 1994年5月21日 ...