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

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
using namespace std; const int maxn = 5000000;
vector<string> vs;
int cnt,ans,n;
int ch[maxn][2];
int val[maxn]; inline int getIdx(char a){
return a-'0';
}
void insert(string st){
int u = 0;
for(int i = 0; i < st.size(); i++){
int k = getIdx(st[i]);
if(!ch[u][k]){
memset(ch[cnt],0,sizeof ch[cnt]);
val[cnt]++;
ans = max(ans,val[cnt]*(i+1));
ch[u][k] = cnt++;
}else{
val[ch[u][k]]++;
ans = max(ans,val[ch[u][k]]*(i+1));
}
u = ch[u][k];
}
}
int main(){ int ncase;
cin >> ncase;
while(ncase--){
vs.clear();
memset(val,0,sizeof val);
memset(ch[0],0,sizeof ch[0]);
cnt = 1;
ans = 0;
cin >> n;
while(n--){
string st;
cin >> st;
insert(st);
}
cout<<ans<<endl;
}
return 0;
}

UVa11488-Hyper Prefix Sets(trie树)的更多相关文章

  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 (字典树)

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

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

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

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

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

  6. Hyper Prefix Sets

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

  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(狂水)

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

  9. UVa 11488 - Hyper Prefix Sets

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

随机推荐

  1. linux crontab定时执行shell脚本

    linux下使用crontab命令被用来提交和管理用户的需要周期性执行的任务,示例如下:crontab -e 编辑周期任务30 21 * * * /etc/init.d/smb restart 每晚的 ...

  2. Lua 与C 交换 第一篇

    编译 windows上编译lua源代码 cl /MD /O2 /W3 /c /DLUA_BUILD_AS_DLL *.c del *.o ren lua.obj lua.o ren luac.obj ...

  3. MYSQL经常使用命令列表

    MYSQL经常使用命令列表 1.系统管理 mysql -h主机地址 -uusername -p 连接MYSQL(在mysql/bin) exit 退出MYSQL命令 mysqladmin -uuser ...

  4. ecshop 后台批量上传商品 完整上传

    ecshop 后台批量上传商品,之所以无法上传,是因为后台上传php文件方法中没有导入商品原图路径 将ecshop根目录中的admin/goods_batch.php文件全部修改为 <?php ...

  5. Maven插件之git-commit-id-plugin

    SCM使用GIT而非SVN时,使用Maven发布,总是会出一些莫名其妙的问题,google查找原因,无意中看到了这个插件; 对于该插件,到目前为止,文档比较少,尤其是中文的文档;全部的信息都包含在项目 ...

  6. crashRpt用法

    从官网上下载crashRpt的源代码,按说明编译出对应的lib和dll 1 在编译crashRpt的时候,在环境变量中设置  crashrptDir=D:\work\AIW\WebMicaps\Web ...

  7. jQuery的理论基础

    概述 jQuery是用JavaScript语言编写的函数库,我们用时,可以直接调用jQuery中相应的函数,对于JavaScript的理解,前面的博客已经介绍过了,在这里只说一下函数的作用,也可以说为 ...

  8. 样品GA的良好理解

    遗传算法演示样本手册模拟 为了更好地理解遗传算法的计算过程,法的各    个主要运行步骤.       例:求下述二元函数的最大值: (1) 个体编码           遗传算法的运算对象是表示个体 ...

  9. 菜鸟学习spring IOC有感

     一.spring IOC思想引入 事实上对于刚開始学习的人来说,在学习IOC的时候确实有点困难,主要是掌握其思想方面存在一丢丢的障碍,可是假设可以跨过这个障碍,则可以高速掌握当中的思想了.单从字 ...

  10. 算法入门经典大赛 Dynamic Programming

    111 - History Grading LCS 103 - Stacking Boxes 最多能叠多少个box DAG最长路 10405 - Longest Common Subsequence ...