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 ...
随机推荐
- hdu 2222 Keywords Search ac自动机模板
题目链接 先整理一发ac自动机模板.. #include <iostream> #include <vector> #include <cstdio> #inclu ...
- 【转】 UIButton上使用UIEdgeInsetsMaketitle跟图片对齐
[转]http://blog.csdn.net/yanxiaoqing/article/details/7230660 默认情况下,不设置的效果,都使居中现实,button为150*150 使用以下设 ...
- servlet tomcat eclipse
网上搜到的很多利用eclipse结合tomcat开发servlet的教程都要修改server.xml 感觉这种方式太粗暴了,server.xml最好是与应用无关的, 这里比较推荐export war的 ...
- Linux----给一个普通用户root权限
问题说明:linux可以通过useradd创建用户.那有没有想过.我们创建的用户怎么样才可以使它得到全部的root权限呢? 解决办法: 1.这是一个可以打80分的办法.就是编辑/etc/sudoers ...
- MySQL----cluster安装
第一步.下载MySQL cluster: http://cdn.mysql.com/Downloads/MySQL-Cluster-7.4/mysql-cluster-gpl-7.4.7-linux- ...
- Xamarin.Android 如何使用Assets目录下的文件
原文:Xamarin.Android 如何使用Assets目录下的文件 个人原创,转载注明出处:http://blog.csdn.net/supluo/article/details/43672411 ...
- Android手势源码浅析-----手势绘制(GestureOverlayView)
Android手势源码浅析-----手势绘制(GestureOverlayView)
- java中输出流OutputStream 类应用实例(转)
OutputStream类该类是字节输出流的抽象类,定义了输出流的各种操作方法.这些方法的说明如表1所示.下面通过实例介绍如何使用OutputStream类向控制台输出字符串信息.步骤如下.(1)创建 ...
- UberX及以上级别车奖励政策(优步北京第一组)
优步北京第一组: 定义为2015年6月1日凌晨前(不含6月1日)激活的司机(以优步后台数据显示为准) 滴滴快车单单2.5倍,注册地址:http://www.udache.com/如何注册Uber司机( ...
- 起启航-华夏互联与杰华网络合体结盟打造本土IT利舰
北京时间2013年9月9日消息: 领先的软件研发企业上海逐一软件科技有限公司与专业互联网推广运营机构南昌杰华网络开发有限公司达成协议,双方将建立紧密合作关系与集团运营体制,并在未来的10个月内进行相应 ...