题意:

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

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. 文件/文件夹比较工具 beyond compare 3.3.10

  2. SqlServer数据文件增长也很快,到底是哪些表增长造成的呢?

    查询数据库中所有表的大小,哪些表的数据量较大 create table #t (name ), rows ), data ), index_size ), unused )) exec sp_MSfo ...

  3. C# 常见集合之前的转换

    1,从System.String[]转到List<System.String> System.String[] str={"str","string" ...

  4. Spring3.0.6定时任务task:scheduled

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  5. jQuery图片无缝滚动JS代码ul/li结构

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. 利用百度地图API,获取经纬度坐标

    利用百度地图API,获取经纬度坐标 代码很简单,但在网上没找到现成的获取地图经纬度的页面. 就是想,给当前页面传递一个经纬度,自动定位到此经纬度.然后可以重新选择,选择完返回经纬度. 效果如下: 源代 ...

  7. js中的script标签

    在页面中用script标签引入javascript文件(<script type="text/javascript" src="js文件地址">&l ...

  8. web api 500 错误

    改了API 方法内容后,就直接F5运行起来. 客户端用WebClient请求,老是返回500错误. 无意中重新编译了WEIAPI项目,客户端就正常了.

  9. android学习笔记31——ADB命令

    使用Adb shell command直接送key event給Androidadb shell input keyevent 7 # for key '0'adb shell input keyev ...

  10. SIGPIPE

    send或者write socket遭遇SIGPIPE信号 当服务器close一个连接时,若client端接着发数据.根据TCP协议的规定,会收到一个RST响应,client再往这个服务器发送数据时, ...