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 ...
随机推荐
- DataList与Repeater嵌套绑定
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="home.aspx.cs&quo ...
- css3写出0.5px的边框
一说到0.5px的边框,我们一般认为是不行的,因为在ps中0.5px的线也是做不出来的,这个计算机的像素有关系. 废话不多说了,0.5px 其实用的是css3新特性,box-shadow:阴影设置 代 ...
- UI—代理简单使用
代理:又叫委托 通俗的说是自己不能办的事 委托给别人去办.比如UITextField,UIAlertView都使用了代理 写代理的步骤: 1.声明代理里面的协议方法(@protocl) 2.声明协议的 ...
- liveusb-creator
liveusb-creator The liveusb-creator is a cross-platform tool for easily installing live operating sy ...
- 75. Sort Colors
Given an array with n objects colored red, white or blue, sort them so that objects of the same colo ...
- 黄聪:WordPress固定链接设置的几种方法
wordpress固定链接设置的一些参数: %year%:基于文章发布的年份,比如2010: %monthnum%:基于文章发布的月份,比如01: %day%:基于文章发布当日,比如06: %hour ...
- HDU 3555 Bomb 数位DP 入门
给出n,问所有[0,n]区间内的数中,不含有49的数的个数 数位dp,记忆化搜索 dfs(int pos,bool pre,bool flag,bool e) pos:当前要枚举的位置 pre:当前要 ...
- DrawTools(画图工具)原始版本
上一篇文章一个优秀的C#开源绘图软件 DrawTools中详细的介绍了DrawTools的几种演化的较高版本的软件的特色与功能. 这篇文章,将介绍一下这款软件的成名版本, 下载地址DrawTool_O ...
- Linux命令(15)查看系统版本信息
一,查看Linux内核版本命令(两种方法) 1.cat /proc/version [user@fgejjw7Z home]$ cat /proc/version Linux version -.el ...
- sql异常
表结构 Id int UncheckedTitle nvarchar(50) CheckedValue nvarchar(1000) CheckedRemark nvarchar(1000) Chec ...