题意:

获得集合中最长前缀长度*有该前缀个数的最大值

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(狂水)的更多相关文章

  1. UVA 11488 Hyper Prefix Sets (Trie)

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  2. uva 11488 - Hyper Prefix Sets(字典树)

    H Hyper Prefix Sets Prefix goodness of a set string is length of longest common prefix*number of str ...

  3. UVA 11488 Hyper Prefix Sets (字典树)

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  4. UVA 11488 Hyper Prefix Sets (字典树)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  5. UVa 11488 - Hyper Prefix Sets

    找 前缀长度*符合该前缀的字符串数 的最大值 顺便练了一下字典树的模板 #include <iostream> #include <cstdio> #include <c ...

  6. 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 ...

  7. 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 ...

  8. Hyper Prefix Sets

    uva11488:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&am ...

  9. UVa11488-Hyper Prefix Sets(trie树)

    H Hyper Prefix Sets Prefix goodness of a set string is length of longest common prefix*number of str ...

随机推荐

  1. windows下做react native官方例子遇到的问题

    1.android/app/build.gradle文件中,指定了版本: compileSdkVersion 23buildToolsVersion "23.0.1" 需要在设置中 ...

  2. 查看当前web服务器的并发连接数

    对于web服务器来说,并发连接数是一个比较重要的参数,通过下面的命令就可以直接查看# netstat -nat | grep ":80"| grep EST | wc -l命令解释 ...

  3. DebugDiag收集Dump的使用说明

    DebugDiag简介 Debug Diagnostic Tool (DebugDiag)是微软提供的工具,可以用来追踪windows平台下的程序崩溃,卡死,内存泄漏等一些疑难问题的原因,按照问题类别 ...

  4. httpClenit的post出现乱码问题

    在使用httpClient.executeMethod(postMethod)的时候,发现一直存在乱码问题,”book is good“被转成”book+is+good“ 返回.查看源码后,发现pos ...

  5. libreoffice转office文档为pdf文档

    libreoffice5.0 --invisible --convert-to pdf:writer_pdf_Export --outdir  "/root/" "bb. ...

  6. 【shell】sort命令

    [root@andon ~]# sort 1 ##常用正序自动排序 101 paul 18 100 102 suan 11 99 103 peter 18 98 id name age score [ ...

  7. 【JdbcTemplete】JdbcTemplete代码详解--模板方法详解

    JdbcTemplete类层次结构 JdbcAccessor:对DataSource数据源进行管理和配置: JdbcOperations:定义了通过JDBC操作数据库的基本操作方法: JdbcTemp ...

  8. 第二次正式java web开发项目的总结(回收站恢复)

    都说互联网行业加班很是厉害,记得前不久网上还晒出了几个大城市互联网行业的加班排名调查,但是我们公司,或者说我们项目组倒是非常的例外,进公司也差不多半年了,才仅仅上个月有一个周六加过一天班而已. 不过好 ...

  9. haproxy实现负载均衡

    一.安装tar zxvf haproxy-1.4.22.tar.gzcd haproxy-1.4.22make TARGET=linux26 PREFIX=/usr/local/haproxy ins ...

  10. 访问修饰符internal

    internal(C# 参考) internal 关键字是类型和类型的成员 访问修饰符. 只有在同一程序集的文件中,内部类型或成员才是可访问的,如下例所示: public class BaseClas ...