题意:

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

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. apache2: Could not reliably determine the server's fully qualified domain name

    错误信息:apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 ...

  2. 服饰行业淘宝商城店铺首页设计报告-转载自http://bbs.paidai.com/topic/88363

    店铺的设计 和 美工是2个完全不同的工作. 很多中小卖家,往往会模糊他们之间的差别. 好比要建造一座金茂大厦,先要有建筑设计师设计图纸,明确好建造的楼层数,具体框架结构,所用材料等等. 然后建筑施工队 ...

  3. 用jquery在必填表单字段前加红星总结

    一.总结: 今天公司项目中要求给表单中的必填字段添加标记,因为表单字段比较多,后期又有可能某些字段会有变化,所以写了一段js代码来给表单添加标记. html代码: js代码: 关键步骤: 1.红星的设 ...

  4. webstorm 10 设置文件的默认编码

    我在使用webstorm时,发现文件的默认编码是GBK 然后我找到了点击此处可以修改这个文件的编码,但是以后新建文件和项目默认生成的文件还是GBK, 设置项目文件的默认编码可以在 File----Se ...

  5. insmod module_param 模块参数

    模块参数 引导模块时,可以向它传递参数.要使用模块参数加载模块,这样写: insmod module.ko [param1=value param2=value ...] 为了使用这些参数的值,要在模 ...

  6. jplayer中动态添加列表曲目(js提取request中的list数据作为js参数使用)

    jplayer 的播放列表使用如下: $(document).ready(function(){ new jPlayerPlaylist({ jPlayer: "#jquery_jplaye ...

  7. (C#) System.BadImageFormatException: An attempt was made to load a program with an incorrect format.

    ASP.NET: System.BadImageFormatException: An attempt was made to load a program with an incorrect for ...

  8. ADF_ADF Faces系列6_ADF数据可视化组件简介之建立Thematic Map Component

    2013-05-01 Created By BaoXinjian

  9. 3. Windows根据端口查进程---ADB 相关报错 ADB server didn't ACK cannot bind ':5037'

    1.ADB server didn't ACK,一般报ADB相关的错误,大部分是端口被占用了 处理方法: 在命令行输入>adb nodaemon server 如果返回: cannot bind ...

  10. python(6)时间戳和北京时间互转,输出当前的时间和推到七天前的日期

    项目发展的需要:(包含时间函数)time datetime 时间戳和北京时间互转 import time import datetime s = '2015-04-17 11:25:30' d = d ...