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 ...
随机推荐
- ACM-ICPC 2018 沈阳赛区网络预赛 K. Supreme Number
A prime number (or a prime) is a natural number greater than 11 that cannot be formed by multiplying ...
- linux无人值守安装介绍(一)
一.术语解释 PXE(Pre-boot ExecutionEnvironment)是由Intel设计的协议,它可以使计算机通过网络而不是从本地硬盘.光驱等设备启动.现代的网卡,一般都内嵌支持PXE的R ...
- HDU 3271 SNIBB
SNIBB Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 3271 ...
- python3--__getattr__和__setattr__捕捉属性的一个引用
__getattr__和__setattr__捕捉属性的一个引用 __getattr__方法是拦截属性点号运算.更确切地说,当通过对未定义(不存在)属性名称和实例进行点号运算时,就会用属性名称为字符串 ...
- python linux安装anaconda
步骤: 1.在清华大学镜像站中下载anaconda版本:https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/ https://mirrors.t ...
- install composer on ubuntu14.04
1.download composer $ sudo apt-get install curl $ curl -sS https://getcomposer.org/installer | php $ ...
- [BZOJ1575] [Usaco2009 Jan]气象牛Baric(DP)
传送门 DP f[i][j]表示前i个中选j个的最优解 预处理g[i][j]表示选i~j对答案的贡献 那么就可以n^3乱搞了! 注意边界 #include <cstdio> #includ ...
- OS X 下iso刻录U盘(系统安装启动盘)
1. 查看盘 $diskutil list /dev/disk0 #: TYPE NAME SIZE IDENTIFIER : GUID_partition_scheme *320.1 GB disk ...
- spring5响应式编程
1.Spring5新特性 2.响应式编程响应式编程:非阻塞应用程序,借助异步和事件驱动还有少量的线程垂直伸缩,而非横向伸缩(分布式集群)当Http连接缓慢的时候,从数据库到Http数据响应中也会 ...
- uva 11991 查询中容器的运用
题目大意:一个n个整数的数组,m条查询指令.(1<=n,m<=100 000)每次询问第k个整数v的下标值,若不存在输出0. #include<iostream> #inclu ...