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 ...
随机推荐
- ESXI主机打开shell后主机警告处理
昨天为了配置snmp监控,将几台ESXI 5.5主机的shell 在控制台上从disable状态修改为enable状态后,登陆vcenter后,发现所有的主机都有警告. 处理过程如下: 选中有警告标志 ...
- OSPF拓扑排错报告
OSPF排错报告 故障点一:PPP链路故障 故障现象: R2和R4之间的PPP链路一会down一会UP 故障分析: 1) ppp 认证类型是否一致 2) ppp chap认证用 ...
- phantomjs,selenium,pyv8,pythonwebkit,,,,,,,,,,,,,
Pyv8,PythonWebKit,Selenium,PhantomJS,Ghost.py 等等.... 快速构建实时抓取集群[searchtb] 定义:http://i.cnblogs.com/Ed ...
- DotNet基础
DotNet基础 URL特殊字符转义 摘要: URL中一些字符的特殊含义,基本编码规则如下: 1.空格换成加号(+) 2.正斜杠(/)分隔目录和子目录 3.问号(?)分隔URL和查询 4.百分号(%) ...
- python学习笔记之11:图像用户界面
这里会介绍如何创建python程序的图像用户界面(GUI),也就是那些带有按钮和文本框的窗口等.目前支持python的所谓“GUI工具包”的有很多,本文简要介绍最成熟的跨平台pythonGUI工具包- ...
- Android开发中验证码的生成
近期在做电商金融类的项目,验证码的生成方法不可缺少.先学习了一种.经过測试好用.从别处学习的代码,稍修改了一下可选择是否支持识别大写和小写.直接上代码. import android.app.Acti ...
- spring html5 拖拽上传多文件
注:这仅仅是一个粗略笔记.有些代码可能没用.兴许会再更新一个能够使用的版本号.不足之处,敬请见谅. 1.spring环境搭建,这里使用的是spring3的jar,须要同一时候引入common-IO 和 ...
- JQuery操作select checkbox radio总结
JQuery是一个非常强大的工具,所以我必须找到它最方便的方法,嘻嘻 Select CRUD: Select搜: 1.val值: $("#selectid").val(); ...
- Recall(检出率)和 Precision(准确性)
这两个方面是模式识别和信息检索使用措施值. 浅显易懂的理解,用以下的图片和公式最好只是. 那么 - 召回率R:用检索到相关文档数作为分子.全部相关文档总数作为分母.即R = A / ( A + C ) ...
- Win7 IIS配置 applicationHost.config 错误:无法识别的特性“setProfileEnvironment” 解决方法
Win7下配置IIS时容易出现这样的错误提示:这是百度知道上面另一个人提问的图,我的显示行号133 解决方法: 到C:\inetpub\history中找到最近一次的applicationHost.c ...