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进制 ...
随机推荐
- 微信小程序开发 -- 01
微信小程序开发基础 -- 开发前的准备 缘由 1月9日张小龙微信小程序正式上线,因为微信,所以小程序从诞生开始就头戴巨大的光环,很多的团队,公司以及开发的个体都眼巴巴的盯着这个小程序.而那个时候我却在 ...
- MAC下解决eclipse卡顿或者运行慢的问题
提示:假设你已经装了固态硬盘,并且有至少8Gb的内存.如果没有的话,带来的性能提升可能不大. 1.eclipse中加载的SDK数量过多会导致程序运行缓慢,解决方法删除plaforms下面用不到的SDK ...
- View Components as Tag Helpers,离在线模板编辑又进一步
在asp.net core mvc中增加了ViewComponent(视图组件)的概念,视图组件有点类似部分视图,但是比部分视图功能更加强大,它更有点像一个控制器. 使用方法 1,定义类派生自View ...
- Disruptor——一种可替代有界队列完成并发线程间数据交换的高性能解决方案
本文翻译自LMAX关于Disruptor的论文,同时加上一些自己的理解和标注.Disruptor是一个高效的线程间交换数据的基础组件,它使用栅栏(barrier)+序号(Sequencing)机制协调 ...
- [POJ 2115} C Looooops 题解(扩展欧几里德)
题目描述 对于C的for(i=A ; i!=B ;i +=C)循环语句,给出A,B,C和k(k表示变量是在k进制下的无符号整数),判断循环次数,不能终止输出"FOREVER". 输 ...
- EF架构~Migration数据迁移的执行顺序
回到目录 对于单个分支项目来说,只要你生成一个migration的版本,就会有一个时间戳文件的对应,而在update-database时,会从最小的时间开始,一直执行到当前版本的migration,而 ...
- Treasure Hunt
Treasure Hunt time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- jquery中div悬浮嵌套按钮效果
<div class="btn_sure_cai" style="margin-left: 0px;" onmouseover="show_hi ...
- Gist - ES6 Promise
The concept of "Promise" Promise is used to asynchronous computations. Introduction " ...
- Angular 4 学习笔记 从入门到实战 打造在线竞拍网站 基础知识 快速入门 个人感悟
最近搞到手了一部Angular4的视频教程,这几天正好有时间变学了一下,可以用来做一些前后端分离的网站,也可以直接去打包web app. 环境&版本信息声明 运行ng -v @angular/ ...