UVa11488-Hyper Prefix Sets(trie树)
H |
Hyper Prefix Sets |
Prefix goodness of a set string is length of longest common prefix*number of strings in the set. For example the prefix goodness of the set {000,001,0011} is 6.You are given a set of binary strings. Find the maximum prefix goodness
among all possible subsets of these binary strings.
Input
First line of the input contains T(≤20) the number of test cases. Each of the test cases start with n(≤50000) the number of strings. Each of the next n lines contains a string containing only 0 and 1. Maximum length of each of these string is 200.
Output
For each test case output the maximum prefix goodness among all possible subsets of n binary strings.
Sample Input Output for Sample Input
4 4 0000 0001 10101 010 2 01010010101010101010 11010010101010101010 3 010101010101000010001010 010101010101000010001000 010101010101000010001010 5 01010101010100001010010010100101 01010101010100001010011010101010 00001010101010110101 0001010101011010101 00010101010101001
|
6 20 66 44 |
Problem Setter : Abdullah Al Mahmud
Special Thanks : Manzurur Rahman Khan
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
using namespace std; const int maxn = 5000000;
vector<string> vs;
int cnt,ans,n;
int ch[maxn][2];
int val[maxn]; inline int getIdx(char a){
return a-'0';
}
void insert(string st){
int u = 0;
for(int i = 0; i < st.size(); i++){
int k = getIdx(st[i]);
if(!ch[u][k]){
memset(ch[cnt],0,sizeof ch[cnt]);
val[cnt]++;
ans = max(ans,val[cnt]*(i+1));
ch[u][k] = cnt++;
}else{
val[ch[u][k]]++;
ans = max(ans,val[ch[u][k]]*(i+1));
}
u = ch[u][k];
}
}
int main(){ int ncase;
cin >> ncase;
while(ncase--){
vs.clear();
memset(val,0,sizeof val);
memset(ch[0],0,sizeof ch[0]);
cnt = 1;
ans = 0;
cin >> n;
while(n--){
string st;
cin >> st;
insert(st);
}
cout<<ans<<endl;
}
return 0;
}
UVa11488-Hyper Prefix Sets(trie树)的更多相关文章
- 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 (字典树)
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(字典树)
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树)
1.给n个只含0.1的串,求出这些串中前缀的最大和. 例1: 0000 0001 10101 010 结果:6(第1.2串共有000,3+3=6) 例2: 01010010101010101010 1 ...
- Hyper Prefix Sets
uva11488:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&am ...
- UVA 11488 Hyper Prefix Sets (字典树)
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- 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 ...
随机推荐
- LNK1207: incompatible PDB format in********
LNK1207: incompatible PDB format in******** VC中错误:LINK : fatal error LNK1207: incompatible PDB forma ...
- 记得有一个奇怪的ORA-04028: cannot generate diana for object
开发商称新一package,目前已经在翻译过程中的一些错误.提示PL/SQL:ORA-00942: table or view does not exists.这是一个非常明显的错误,即要么是表不存在 ...
- thinkphp框架的相关总结
参考链接地址:http://gongwen.sinaapp.com/article-205.html 1. 模板中不能使用的标签 {$content} {$i} 2. If标签 如: <if c ...
- Linux下多线程查看工具(pstree、ps、pstack) (转)
1. pstree pstree以树结构显示进程$ pstree -p work | grep adsshd(22669)---bash(22670)---ad_preprocess(4551)-+- ...
- POJ 1515 Street Directions
题意: 一幅无向图 将尽量多的无向边定向成有向边 使得图强连通 无向图保证是连通的且没有重边 思路: 桥必须是双向的 因此先求边双连通分量 并将桥保存在ans中 每一个双连通分量内的边一定都 ...
- FREESWITCH SEESION
SESSION SESSION为FS的核心概念之一,所以需要拿出来专门的分析下. 从以下几个方面进行分析,结构类型,资源的管理,对于呼叫的意义,规格. 1.结构类型 每一次呼叫会申请一个session ...
- BZOJ 2783 JLOI 2012 树 乘+二分法
标题效果:鉴于一棵树和一个整数s,问中有树木几个这样的路径,点和担保路径==s,深度增量点. 这一数额的输出. 思维:用加倍的想法,我们可以O(logn)在时间找点他第一n.因为点权仅仅能是正的,满足 ...
- Test SRM Level Two: CountExpressions, Brute Force
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=8157 这道题目跟扑克牌算24的题目比较像,但要简单一些.点击查 ...
- mvc图片地址
System.Web.HttpContext.Current.Server.MapPath(@"~\Images\radio1.png");
- 配置Tomcat的日志系统
成功配置tomcat的log4j日志系统,格式:HTML+每天以yyyy-mm-dd.log命名的日志文件 一.引言: 实习单位让用log4j配置webapp的日志系统,要求产生的日志文件是html格 ...