HDU 11488 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
题目大意:
如果a表示公共前缀的长度,b表示含有这个前缀的字符串个数,问你a*b的最大值。
解题思路:
建立一棵Trie树,边建边查,直接更新 长度乘以个数的最大值
解题代码:
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
using namespace std; const int maxn=500000;
int tree[maxn][2];
int val[maxn],cnt;
int n,ans; void insert(string st){
int s=0;
for(int i=0;i<st.length();i++){
if( tree[s][st[i]-'0']==0 ) tree[s][st[i]-'0']=++cnt;
s=tree[s][st[i]-'0'];
val[s]++;
if((i+1)*val[s]>ans) ans=(i+1)*val[s];
}
} void initial(){
cnt=ans=0;
memset(val,0,sizeof(val));
memset(tree,0,sizeof(tree));
} void solve(){
cin>>n;
for(int i=0;i<n;i++){
string st;
cin>>st;
insert(st);
}
cout<<ans<<endl;
} int main(){
int t;
cin>>t;
while(t-- >0){
initial();
solve();
}
return 0;
}
HDU 11488 Hyper Prefix Sets (字符串-Trie树)的更多相关文章
- 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(字典树)
H Hyper Prefix Sets Prefix goodness of a set string is length of longest common prefix*number of str ...
- 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 ...
- UVa11488-Hyper Prefix Sets(trie树)
H Hyper Prefix Sets Prefix goodness of a set string is length of longest common prefix*number of str ...
- HDU 1251 统计难题 (字符串-Trie树)
统计难题 Problem Description Ignatius近期遇到一个难题,老师交给他非常多单词(仅仅有小写字母组成,不会有反复的单词出现),如今老师要他统计出以某个字符串为前缀的单词数量(单 ...
- UVA 11488 Hyper Prefix Sets (字典树)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- 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 ...
随机推荐
- nodeJs入门笔记(一)
node将"HTTP服务器"这一层抽离,直接面向浏览器用户 如PHP运行之前先要配置一个功能强大而复杂的HTTP 服务器,譬如Apache.IIS 或Nginx,还需要将PHP 配 ...
- java面向对象之 多态 Polymorphism
多态(Polymorphism):用我们通俗易懂的话来说就是子类就是父类(猫是动物,学生也是人),因此多态的意思就是:父类型的引用可以指向子类的对象. 1.多态的含义:一种类型,呈现出多种状态 主要讨 ...
- python进阶--打包为exe文件
一.Python打包为EXE文件有不少方案,比较常用的有下面两种方式: 1.使用py2exe 详细介绍:http://www.cnblogs.com/jans2002/archive/2006/09/ ...
- Adobe Acrobat 9 Pro 简体中文正式版(免激活)
软件语言:简体中文版本性质:官方正式版(免激活,非破解) Mac & PC [SN]: 1118-4018-6583-4956-2486-7805 修改 Abcpy.ini 可实现免序列号免激 ...
- Golang网络库中socket阻塞调度源码剖析
本文分析了Golang的socket文件描述符和goroutine阻塞调度的原理.代码中大部分是Go代码,小部分是汇编代码.完整理解本文需要Go语言知识,并且用Golang写过网络程序.更重要的是,需 ...
- poj1665
#include <stdio.h> #include <stdlib.h> #define pi 3.1415926 int main() { float dia,tim; ...
- 数据结构中La表的数据合并到Lb表中
实验描述:La表中的数据为(3,5,8,11) Lb 表中的数据为(2,6,8,9,11,15,20) 将La表中的数据而不存在Lb表的数据插入到Lb表中,从而实现并集操作. 出现的问题:最后实现的 ...
- JS 严格模式
标志 "use strict"; //老版本浏览器会自动忽略 调用 //整个文件调用 (function(){ "use strict"; })(); //单个 ...
- SQL学习之高级联结(自联结、自然联结、外联接)
create table Customers( Id ,), Company ) null, Name ) null ) insert into Customers values('Fun4All', ...
- 现在网页中流行的css3样式
1.鼠标放在圆形图片中,图片渐渐的变方形[17素材头像的特效,觉得不错就研究下来了 ———— 17sucai.com] img{border-radius:50%;transition: all .4 ...