UVA 11488-Hyper Prefix Sets(Trie)
题意:
给一个01串的集合,一个集合的幸运值是串的个数*集合中串的最大公共前缀 ,求所有子集中最大幸运值
分析:
val[N]表示经过每个节点串的个数求幸运值 求就是每个节点值*该节点的深度 搜一遍树求出最大值
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int>P;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define N 10000010
#define read freopen("in.txt", "r", stdin)
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = ;
struct Trie{
int ch[N][];
int val[N],num;
void init(){
num=;
memset(ch[],,sizeof(ch[]));
memset(val,,sizeof(val));
}
//建树
void build(char *s){
int u=,len=strlen(s);
for(int i=;i<len;++i){
int v=s[i]-'';
if(!ch[u][v]){
memset(ch[num],,sizeof(ch[num]));
ch[u][v]=num++;
}
u=ch[u][v];
val[u]++;
}
}
//bfs
ll query(){
queue<P>q;
ll maxv=;
q.push(P(,));
while(!q.empty()){
P p=q.front();
q.pop();
int u=p.first;
int h=p.second;
maxv=max(maxv,1LL*val[u]*h);
for(int i=;i<;++i){
if(ch[u][i]){
q.push(P(ch[u][i],h+));
}
}
}
return maxv;
}
}trie;
int main()
{
int t,n;
char str[];
scanf("%d",&t);
for(int o=;o<t;++o){
trie.init();
scanf("%d",&n);
for(int i=;i<n;++i){
scanf("%s",str);
trie.build(str);
}
printf("%lld\n",trie.query());
}
return ;
}
UVA 11488-Hyper Prefix Sets(Trie)的更多相关文章
- UVA - 11488 Hyper Prefix Sets(trie树)
1.给n个只含0.1的串,求出这些串中前缀的最大和. 例1: 0000 0001 10101 010 结果:6(第1.2串共有000,3+3=6) 例2: 01010010101010101010 1 ...
- uva 11488 - Hyper Prefix Sets(字典树)
H Hyper Prefix Sets Prefix goodness of a set string is length of longest common prefix*number of str ...
- UVA 11488 Hyper Prefix Sets (字典树)
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- UVA 11488 Hyper Prefix Sets (字典树)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- HDU 11488 Hyper Prefix Sets (字符串-Trie树)
H Hyper Prefix Sets Prefix goodness of a set string is length of longest common prefix*number of str ...
- UVA 11488 Hyper Prefix Sets (Trie)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- uva 11488 Hyper Prefix Sets(狂水)
题意: 获得集合中最长前缀长度*有该前缀个数的最大值 Prefix goodness of a set string is length of longest common prefix*number ...
- UVa 11488 - Hyper Prefix Sets
找 前缀长度*符合该前缀的字符串数 的最大值 顺便练了一下字典树的模板 #include <iostream> #include <cstdio> #include <c ...
- UVa11488-Hyper Prefix Sets(trie树)
H Hyper Prefix Sets Prefix goodness of a set string is length of longest common prefix*number of str ...
随机推荐
- OO之装饰者模式
以下为装饰者模式详解: 引子: 假如有一个快餐店,基本种类分为米饭,水饺,粉面等,但每一种类型的快餐又可以搭配不同的料,如米饭可以点各种不同的菜(排骨,青菜,土豆等),如果按照一般的设计,快餐为基类, ...
- linux安装软件命令
tar.bz2的解压: tar -jxvf FileName.tar.bz2 然后安装: cd FileName ./configure make make install rpm 包的安装: rpm ...
- 如何修改SVN中的用户名和密码
删除掉C:\Users\Administrator\Application Data\Subversion\auth\svn.simple文件夹下的文件即可.再次访问时,会弹出要求输入用户名和密码. ...
- [转]popwindow用法
[转]弹出窗口的两种实现方式 PopupWindow 和 Activity 链接:http://www.cnblogs.com/winxiang/archive/2012/11/20/2778729 ...
- JavaScript中常谈的对象
为浏览器编写代码时,总少不了window对象 window对象表示JavaScript程序的全局环境 同时 也表示应用的主窗口 到处都是对象 window对象 常用的属性和方法介绍 location ...
- 1025: [SCOI2009]游戏 - BZOJ
Description windy学会了一种游戏.对于1到N这N个数字,都有唯一且不同的1到N的数字与之对应.最开始windy把数字按顺序1,2,3,……,N写一排在纸上.然后再在这一排下面写上它们对 ...
- c++ deque 双端队列
双端队列: 函数 描述 c.assign(beg,end)c.assign(n,elem) 将[beg; end)区间中的数据赋值给c.将n个elem的拷贝赋值给c. c.at(idx) 传回索引 ...
- replace()替换文字
var test = text.innerHTML; b = test.replace(/任晓强/g,"你好"); console.log(b); html: <div id ...
- CNKI翻译助手-连接数据库失败
IP并发数限制,老师说西工大的CNKI才20个并发指标,HPU自不必说.但是我略表怀疑,这只是翻译助手而已,就像百度翻译和百度数据库的区别,如何验证呢?去校外用该助手,如果能用,那么就不是IP并发限制 ...
- [itint5]下一个排列
http://www.itint5.com/oj/#6 首先,试验的时候要拿5个来试,3,4个都太少了.好久没做所以方法也忘了,是先从后往前找到第一个不合顺序的,然后在后面找到比这个大的最小的来交换, ...