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 ...
随机推荐
- 快照、克隆,xshell优化,Linux历史
目录 一.虚拟拍照功能 二.虚拟机克隆功能 三.Xshell的优化 四.介绍Linux历史 一.虚拟拍照功能 1.拍摄快照 关机状态拍照 关机命令:shutdown -h now 或者 init 0 ...
- 【转】ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
为了加强安全性,MySQL5.7为root用户随机生成了一个密码,在error log中,关于error log的位置,如果安装的是RPM包,则默认是/var/log/mysqld.log. 一般可通 ...
- python 实现计算器功能 输入字符串,输出相应结果
import re formul='1 - 2 *( (6 0- 30+(0-40/5) * (9-2* 5/3 +7 /3*99/4*2998 +10 *568/14)) - (-4*3) / (1 ...
- Python正则表达式与hashlib模块
菜鸟学python第十六天 1.re模块(正则表达式) 什么是正则表达式 正则表达式是一个由特殊字符组成的序列,他能帮助对字符串的某种对应模式进行查找. 在python中,re 模块使其拥有全部的正则 ...
- python基础学习笔记——collections模块
在内置数据类型(dict.list.set.tuple)的基础上,collections模块还提供了几个额外的数据类型:Counter.deque.defaultdict.namedtuple和Ord ...
- java null 空指针
对于Java程序员来说,null是令人头痛的东西.时常会受到空指针异常(NPE)的骚扰.连Java的发明者都承认这是他的一项巨大失误.Java为什么要保留null呢?null出现有一段时间了,并且我认 ...
- python 跨域
CORS跨域请求 CORS即Cross Origin Resource Sharing 跨域资源共享, 那么跨域请求还分为两种,一种叫简单请求,一种是复杂请求~~ 简单请求 HTTP方法是下列方法之一 ...
- Java设计模式学习二
Java设计思想之单例模式 单例模式(Singleton Pattern)是Java中最常见的设计模式之一.这种类型的设计模式属于创建型模式,它提供了一种创建对象的最佳方式. 这种模式涉及到一个单一的 ...
- 【javascript面试题】之一
1.求y和z的值是多少?<script type="text/javascript">var x = 1;var y = 0;var z = 0;function ad ...
- Java-使用哈希码比较对象的值
在一些特殊的情况下使用 package com.tj; import java.io.File; public class MyHash { public static void main(Strin ...