uva 11488 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.
SampleInput
4
4
0000
0001
10101
010
2
01010010101010101010
11010010101010101010
3
010101010101000010001010
010101010101000010001000
010101010101000010001010
5
01010101010100001010010010100101
01010101010100001010011010101010
00001010101010110101
0001010101011010101
00010101010101001
SampleOutput
6
20
66
44
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int sum;
char str[205];
struct Trie
{
int cnt;
Trie *next[5];
Trie()
{
cnt=0;
memset(next,NULL,sizeof(next));
}
}; void Insert(Trie *p,char ch[],int len)
{
for(int i=0;i<strlen(ch);i++)
{
p->cnt++;
sum = max(sum,p->cnt*i);
if(p->next[ ch[i]-'0' ]==NULL)
p->next[ ch[i]-'0']=new Trie;
p = p->next[ch[i]-'0'];
}
p->cnt++;
sum = max(sum,p->cnt*(int)strlen(ch));
}
int main()
{
int T,n;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
Trie *root=new Trie;
sum=0;
while(n--)
{
scanf("%s",str);
Insert(root,str,0);
}
printf("%d\n",sum);
}
return 0;
}
uva 11488 Hyper Prefix Sets(狂水)的更多相关文章
- 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(字典树)
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 (字典树)
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(trie树)
1.给n个只含0.1的串,求出这些串中前缀的最大和. 例1: 0000 0001 10101 010 结果:6(第1.2串共有000,3+3=6) 例2: 01010010101010101010 1 ...
- 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 ...
- Hyper Prefix Sets
uva11488:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&am ...
- UVa11488-Hyper Prefix Sets(trie树)
H Hyper Prefix Sets Prefix goodness of a set string is length of longest common prefix*number of str ...
随机推荐
- Dom之表单提交与默认行为
一.button提交表单 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&q ...
- TKinter之菜单
菜单的分类也较多,通常可以分为下拉菜单.弹出菜单. 1.使用Menu类创建一个菜单 2.add_command添加菜单项,如果该菜单是顶层菜单,则添加的菜单项依次向右添加. 如果该菜单时顶层菜单的一个 ...
- C#读写txt文件的两种方法介绍
C#读写txt文件的两种方法介绍 1.添加命名空间 System.IO; System.Text; 2.文件的读取 (1).使用FileStream类进行文件的读取,并将它转换成char数组,然后输出 ...
- 解决:mvn archetype:create Abstract class or interface 'org.apache.maven.artifact.repository.ArtifactRepository' cannot be instantiated
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2 .3:create (default- ...
- asp.net中virtual和abstract的区别分析
这篇文章主要介绍了asp.net中virtual和abstract的区别,较为详细的分析了virtual与abstract的概念与具体用法,并以实例的形式予以总结归纳,需要的朋友可以参考下 本文实例分 ...
- IOS开发-视频,音频,录音简单总结
/***** * 1. 视频播放 * * @格式:mp4 mov m4v m2v 3gp 3g2 * * @系统框架使用:#import <MediaPlayer/MediaPlayer.h ...
- Matlab 计算大数的阶乘
http://hi.baidu.com/dreamflyman/item/11e920165596280fd0d66d9f >> syms k;>> kfac=sym('k!' ...
- Python 通过print将数据保存到文件中
1. Print them to screen man = [] other = [] try: data = open('sketch.txt') for each_line in data: tr ...
- Android框架
http://blog.163.com/vicent_zxb/blog/static/1858861312011488262665/ (一)Android系统框架详解 Android采用分层的架构,分 ...
- [Issue]repo/repo init-解决同步源码Cannot get http://gerrit.googlesource.com/git-repo/clone.bundle
1. 前两天想搭建freescale L3.0.35_4.1.0_BSP包,结果LTIB环境搭建好,也编译出rootfs/uboot/kernel的Image了,但是准备移植uboot的时候发现ubo ...