H

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.

Sample Input                             Output for Sample Input

4

4

0000

0001

10101

010

2

01010010101010101010

11010010101010101010

3

010101010101000010001010

010101010101000010001000

010101010101000010001010

5

01010101010100001010010010100101

01010101010100001010011010101010

00001010101010110101

0001010101011010101

00010101010101001

 

6

20

66

44


Problem Setter : Abdullah Al Mahmud

Special Thanks : Manzurur Rahman Khan

题目大意:

如果a表示公共前缀的长度,b表示含有这个前缀的字符串个数,问你a*b的最大值。

解题思路:

建立一棵Trie树,边建边查,直接更新 长度乘以个数的最大值

解题代码:

#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
using namespace std; const int maxn=500000;
int tree[maxn][2];
int val[maxn],cnt;
int n,ans; void insert(string st){
int s=0;
for(int i=0;i<st.length();i++){
if( tree[s][st[i]-'0']==0 ) tree[s][st[i]-'0']=++cnt;
s=tree[s][st[i]-'0'];
val[s]++;
if((i+1)*val[s]>ans) ans=(i+1)*val[s];
}
} void initial(){
cnt=ans=0;
memset(val,0,sizeof(val));
memset(tree,0,sizeof(tree));
} void solve(){
cin>>n;
for(int i=0;i<n;i++){
string st;
cin>>st;
insert(st);
}
cout<<ans<<endl;
} int main(){
int t;
cin>>t;
while(t-- >0){
initial();
solve();
}
return 0;
}

HDU 11488 Hyper Prefix Sets (字符串-Trie树)的更多相关文章

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

  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 (Trie)

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

  5. UVa11488-Hyper Prefix Sets(trie树)

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

  6. HDU 1251 统计难题 (字符串-Trie树)

    统计难题 Problem Description Ignatius近期遇到一个难题,老师交给他非常多单词(仅仅有小写字母组成,不会有反复的单词出现),如今老师要他统计出以某个字符串为前缀的单词数量(单 ...

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

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

  8. UVa 11488 - Hyper Prefix Sets

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

  9. uva 11488 Hyper Prefix Sets(狂水)

    题意: 获得集合中最长前缀长度*有该前缀个数的最大值 Prefix goodness of a set string is length of longest common prefix*number ...

随机推荐

  1. SQL Server 查看数据页面

    第一步: 找到表的第一页dbcc ind(db_name,table_name,-1); 例子. dbcc ind(studio,person,-1);# pageFID  是文件号   pagePI ...

  2. gdb运行时结合汇编堆栈分析

    一.从源代码文件到可执行文件         从C文件到可执行文件,一般来说需要两步,先将每个C文件编译成.o文件,再把多个.o文件和链接库一起链接成可执行文件.但具体来说,其实是分为四步,下面以ex ...

  3. 链表-Reverse Linked List

    /** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * } ...

  4. 利用sass构建组件化的ui库

    创建公用的Sass项目模板 在做项目时,不管什么项目,他们之间总是有一些可以共用的部分.比如说重置样式.公用样式.模块组件.UI库等.那么在Sass项目中也是如此.为了避免在每个项目中做一些相同的事情 ...

  5. Android开发10.3:UI组件GridView网格视图

    GridView(网格视图) 概述 GridView用于在界面上按行.列分布的方式来显示多个组件         GridView和ListView有共同的父类 : AbsListView       ...

  6. 提高你的Java代码质量吧:使用构造函数协助描述枚举项

    一.分析 一般来说,我们经常使用的枚举项只有一个属性,即排序号,其默认值是从0.1.2... ....但是除了排序号外,枚举还有一个(或多个)属性. 二.场景 比如,可以通过枚举构造函数声明业务值,定 ...

  7. HDU 5024 Wang Xifeng&#39;s Little Plot 搜索

    pid=5024">点击打开链接 Wang Xifeng's Little Plot Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  8. java写文件时,输出不完整的原因以及解决方法

    在java的IO体系中,写文件通常会用到下面语句 BufferedWriter bo=new BufferedWriter(new FileWriter("sql语句.txt")) ...

  9. 从一句SQL得出的启示

    select count(*) + 1 from `table` where rank > (select rank from `table` where id = *) 上面那句SQL 给了我 ...

  10. 软件介绍:搜索工具 Listary

    如今的互联网时代,搜索的重要性我想大家都是认可的.网上的知识浩如烟海,而搜索引擎是通向这些知识的入口.谷歌.百度等搜索引擎给我们带来了极大的便利,也无怪他们成长为如今的互联网巨头. 然而储存在个人硬件 ...