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进制 ...
随机推荐
- Windows系统前端常用PS快捷键:
1.设置滚轮放大缩小: 编辑--首选项--常规--用滚轮缩放 2.V 移动 ctrl+v 自动选中(图层), 3.M 选框 Shift+M 变换形状 Alt :确定圆形/矩形中心 Shift: 圆形/ ...
- Mac 上Python多版本切换
Mac上自带了Python2.x的版本,有时需要使用Python3.x版本做开发,但不能删了Python2.x,可能引起系统不稳定,那么就需要安装多个版本的Python. 1.安装Python3.x版 ...
- js___原生js轮播
原生js轮播 作为一名前端工程师,手写轮播图应该是最基本掌握的技能,以下是我自己原生js写的轮播,欢迎指点批评: 首先css代码 a{text-decoration:none;color:#3DBBF ...
- Navicat连接Oracle报错_Cannot load OCI DLL 87
原因: Oracle需要装client才能让第三方工具通过OCI(Oracle Call Interface)来连接. 解决方案: 1. 去oracle官网下载Instant Client 11, 或 ...
- winform / Dev全局皮肤组件
话不多说先上效果图. 由于这是单独的测试项目, 用于演示Dev控件的皮肤样式, 所以上面只是演示了部分控件的效果. 下面则是一些实际项目中的截图: Dev的控件样式不仅美观丰富, 上面仅皮肤设置就有4 ...
- 简单理解js闭包
什么是闭包?我们先来看一段代码: function a() { var n = 0; function inc() { n++; console.log(n); } inc(); inc(); } a ...
- [leetcode-604-Design Compressed String Iterator]
Design and implement a data structure for a compressed string iterator. It should support the follow ...
- 【Android Developers Training】 80. 管理网络使用
注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...
- 2.如何实现使用VBS脚本程序对直播间自动评论
前言:本文使用的是VBS脚本,实现了对繁星直播自动登录,自动进入房间并且自动评论. 前提准备:把需要刷的评论放到mysql中,再使用vbs读出评论 -------------------------- ...
- Vijos 1004 伊甸园日历游戏 博弈
描述 Adam和Eve玩一个游戏,他们先从1900.1.1到2001.11.4这个日期之间随意抽取一个日期出来.然后他们轮流对这个日期进行操作: 1 : 把日期的天数加1,例如1900.1.1变到19 ...