HDU 6034---Balala Power!(搜索+贪心)

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.
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)
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
using namespace std;
typedef long long LL;
const int MAXN=1e5+;
const LL MOD = 1e9+;
char str[MAXN];
int k[][MAXN];
int mp[];
int ans[];
int temp;
int check(int a[])
{
int num=;
for(int i=;i<;i++)
num+=a[i];
return num;
}
int pp()
{
for(int i=;i<;i++)
if(mp[i]==) return i;
} void dfs(int dep,int o[])
{
if(dep<) return ;
int maxn=-;
int oo[] , ct=,pos=-;
memset(oo,,sizeof(oo));
for(int i=;i<=;i++)
{
if(maxn<k[i][dep]&&o[i]==)
maxn=k[i][dep];
}
for(int i=;i<=;i++)
{
if(maxn==k[i][dep]&&o[i]==)
{
oo[i]=;
o[i]=;
ct++;
pos=i;
}
}
if(ct==) return ;
if(ct==){
if(check(mp)==&&pos==pp()) ans[pos]=;
else ans[pos]=temp++;
mp[pos]=;
}
else if(dep==){
for(int i=;i<;i++)
{
if(maxn==k[i][dep]&&oo[i]==)
{
if(check(mp)==&&i==pp()) ans[i]=;
else ans[i]=temp++;
mp[i]=;
}
}
}
else dfs(dep-,oo);
if(check(o)>) dfs(dep,o);
}
LL Pow(LL a, LL b){
LL ans = ;
while(b){
if(b & ) ans = (ans * a) % MOD;
b>>=;
a = (a * a ) % MOD;
}
return ans;
} int main()
{
int T,n,L,l,cas=;
int one[];
while(scanf("%d",&n)!=-)
{
L=;
for(int i=;i<;i++) one[i]=,mp[i]=;
memset(k,,sizeof(k));
///memset(ans,0,sizeof(ans));
for(int i=;i<n;i++)
{
scanf("%s",str);
mp[str[]-'a']=;
l=strlen(str);
if(l>L) L=l;
for(int j=;j<l;j++) k[str[j]-'a'][l-j-]++;
}
for(int i=;i<;i++)
{
for(int j=;j<L+;j++)
{
k[i][j+]+=k[i][j]/;
k[i][j]=k[i][j]%;
}
}
temp=;
dfs(L+,one);
///for(int i=0;i<26;i++) cout<<ans[i]<<" "; cout<<endl;
LL res=0;
for(int i=;i<;i++)
{
for(int j=;j<L+;j++)
{
///res+=(25-ans[i])*Pow(26,j)*k[i][j];
res = (res+((-ans[i])*Pow(,j) % MOD)*k[i][j]%MOD)%MOD;
}
}
printf("Case #%d: %lld\n",cas++,res);
}
return ;
}
HDU 6034---Balala Power!(搜索+贪心)的更多相关文章
- HDU 6034 Balala Power!(贪心+排序)
Balala Power! Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- HDU 6034 - Balala Power! | 2017 Multi-University Training Contest 1
/* HDU 6034 - Balala Power! [ 大数进位,贪心 ] 题意: 给一组字符串(小写英文字母),将上面的字符串考虑成26进制数,每个字母分配一个权值,问这组数字加起来的和最大是多 ...
- 2017 Multi-University Training Contest - Team 1 1002&&HDU 6034 Balala Power!【字符串,贪心+排序】
Balala Power! Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- hdu 6034 Balala Power!
Balala Power! Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- 2017ACM暑期多校联合训练 - Team 1 1002 HDU 6034 Balala Power! (字符串处理)
题目链接 Problem Description Talented Mr.Tang has n strings consisting of only lower case characters. He ...
- HDU 6034 Balala Power!【排序/进制思维】
Balala Power![排序/进制思维] Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java ...
- HDU 6034 Balala Power! —— Multi-University Training 1
Talented Mr.Tang has nn strings consisting of only lower case characters. He wants to charge them wi ...
- HDU 6034 Balala Power! (贪心+坑题)
题意:给定一个 n 个字符串,然后问你怎么给 a-z赋值0-25,使得给定的字符串看成26进制得到的和最大,并且不能出现前导0. 析:一个很恶心的题目,细节有点多,首先是思路,给定个字符一个权值,然后 ...
- hdu 5335 Walk Out 搜索+贪心
Walk Out Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total S ...
- 6034 Balala Power! (17多校)
题目大意:给出的字符串,每个字符建立一种与0-25的对应关系.然后每个字符串看成是一个26进制的数.问能获得的数的总和的最大值.(最后对1e9+7取模). 题目思考:把每个字符的贡献值看做一个26进制 ...
随机推荐
- 关于URL的理解
引言 URL,是统一资源定位符(Uniform Resource Locator)的缩写,一个URL就是一个特定资源在网络上的地址.理论上讲,一个URL指向一个唯一的资源,这个资源可以使一个HTML页 ...
- mailto调用本地默认客户端发邮件
下面介绍如何利用 Mailto功能: 实现 Mailto的基本html代码: <a href="mailto:123@qq.com">点击这里发邮件!</a> ...
- Ruby中文乱码问题
中文乱码问题 解决方法为只要在文件开头加入 # -*- coding: UTF-8 -*-(EMAC写法) 或者 #coding=utf-8 就行了. 源代码文件中,若包含中文编码,则需要注意两点: ...
- 深入理解 JavaScript 事件循环(一)— event loop
引言 相信所有学过 JavaScript 都知道它是一门单线程的语言,这也就意味着 JS 无法进行多线程编程,但是 JS 当中却有着无处不在的异步概念 .在初期许多人会把异步理解成类似多线程的编程模式 ...
- Spring Mvc Url和参数名称忽略大小写
在开发过程中Spring Mvc 默认 Url和参数名称都是区分大小写的 比如:www.a.com/user/getUserInfo?userId=1 www.a.com/user/getuserIn ...
- 关于MATLAB处理大数据坐标文件201763
目前已经找出26条特征 ,但是提交数据越来越少,给我的感觉是随机森林画的范围越来越小,输出的机器数据也越来越少,我自认为特征没太大问题 我已经将不懂之处列了出来,将于明天咨询大师级人物
- javaScript高级程序设计笔记 1
核心 ECMAScript 文档对象模型 DOM 浏览器对象模型 BOM 延迟脚本 defer typeof操作符 判断字符类型 返回 undefined boolean s ...
- 详解ES6中的 let 和const
前 言 JRedu ECMAScript 6 是 JavaScript 语言教程,全面介绍 ECMAScript 6 新引入的语法特性. ES6 与上一个版本 ES5 的所有不同之处,对涉及的语 ...
- 音乐API之QQ音乐
欢迎大家来到我的博客,这是我在博客园写的第一篇文章,但不会是最后一篇,希望大家多多关注我,支持我哦!正文开始,今天我们要讲的是QQ音乐的API,都是来源于官方的地址,以前我也想写一个,但百度谷歌之后都 ...
- H5学习第三周
今天主要总结弹性布局 flex使用 1.给父容器添加display flex/inline-flex;属性 2.父容器可以使用的属性值有 >>>flex-direction 属性决定 ...