uva 11488 - Hyper Prefix Sets(字典树)
|
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 |
字典树,每条边记录一下深度。
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <string>
using namespace std; struct edge{
int u , v , letter , sum , dep;
edge(int a = 0 , int b = 0 , int c = 0 , int d = 0 , int f = 0){
u = a , v = b , letter = c , sum = d , dep = f;
}
};
vector<edge> e;
vector<int> head , next;
int ans; void add(int u , int v , int letter , int sum , int dep){
e.push_back(edge(u , v , letter , sum , dep));
next.push_back(head[u]);
head[u] = next.size()-1;
head.push_back(-1);
} void addLibrary(string s){
int u = 0 , index = 0;
while(index < s.length()){
int Next = head[u];
while(Next != -1){
if(e[Next].letter == s[index]-'0') break;
Next = next[Next];
}
if(Next == -1) break;
e[Next].sum++;
index++;
u = e[Next].v;
}
while(index < s.length()){
add(u , head.size() , s[index]-'0' , 1 , index+1);
index++;
u = head.size()-1;
}
}
void initial(){
e.clear();
next.clear();
head.clear();
head.push_back(-1);
ans = 0;
} void readcase(){
string s;
int n;
scanf("%d" , &n);
getchar();
while(n--){
cin >> s;
//cout <<"+"<<s<<endl;
addLibrary(s);
}
for(int i = 0; i < e.size(); i++){
if(e[i].sum*e[i].dep > ans) ans = e[i].sum*e[i].dep;
}
printf("%d\n" , ans);
} int main(){
int t;
scanf("%d" , &t);
while(t--){
initial();
readcase();
}
return 0;
}
uva 11488 - Hyper Prefix Sets(字典树)的更多相关文章
- UVA 11488 Hyper Prefix Sets (字典树)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- 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 ...
- 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
找 前缀长度*符合该前缀的字符串数 的最大值 顺便练了一下字典树的模板 #include <iostream> #include <cstdio> #include <c ...
- uva 11488 Hyper Prefix Sets(狂水)
题意: 获得集合中最长前缀长度*有该前缀个数的最大值 Prefix goodness of a set string is length of longest common prefix*number ...
- 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 ...
- 208 Implement Trie (Prefix Tree) 字典树(前缀树)
实现一个 Trie (前缀树),包含 insert, search, 和 startsWith 这三个方法.注意:你可以假设所有的输入都是小写字母 a-z.详见:https://leetcode.co ...
- 【leetcode】208. Implement Trie (Prefix Tree 字典树)
A trie (pronounced as "try") or prefix tree is a tree data structure used to efficiently s ...
随机推荐
- (转)WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!
[root@bak1 bak]# scp gwsyj.sql.gz root@192.168.21.65:/data/dbdata/ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ...
- ThreadLocalClient小应用
今天遇到hibernate.find就会进行权限配置,如果某处想要跳过权限配置,则可以如下 ThreadLocalClient.get().envParamMap.put(DataAuthority. ...
- saltstack管理八之常用执行模块
所有执行模块: http://docs.saltstack.cn/zh_CN/latest/ref/states/all/index.html 常用模块:cmd, cron, file, mount, ...
- IPy模块--IP地址处理
Python之实用的IP地址处理模块IPy 实用的IP地址处理模块IPy 在IP地址规划中,涉及到计算大量的IP地址,包括网段.网络掩码.广播地址.子网数.IP类型等 别担心,Ipy模块拯救你.Ipy ...
- Java包(package)详解
java包的作用是为了区别类名的命名空间 1.把功能相似或相关的类或接口组织在同一个包中,方便类的查找和使用.. 2.如同文件夹一样,包也采用了树形目录的存储方式.同一个包中的类名字是不同的,不同的包 ...
- enable apache2 rewrite_mod on ubuntu14.04
$ cd /etc/apache2/mods-enable $ ln -s rewrite.load ../mods-available/rewrite.load change "Allow ...
- [android开发篇]权限列表
http://www.open-open.com/lib/view/open1425868811607.html
- LINQ-内部联接
一.简单键联接 下面的示例创建两个集合,其中包含两种用户定义类型 Person 和 Pet 的对象. 查询使用 C# 中的 join 子句将 Person 对象与 Owner 是该 Person 的 ...
- 九度oj 题目1109:连通图
题目描述: 给定一个无向图和其中的所有边,判断这个图是否所有顶点都是连通的. 输入: 每组数据的第一行是两个整数 n 和 m(0<=n<=1000).n 表示图的顶点数目,m 表示图中边的 ...
- vamare下centos7.0 动态获取ip报错问题
CentOS7 Failed to start LSB: Bring up/down解决方法 centos7.0中service network restart重启报错的问题 报错信息: /etc/i ...