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. RequireJS和JQuery的模块化编程

    基于RequireJS和JQuery的模块化编程 由于js的代码逻辑越来越重,一个js文件可能会有上千行,十分不利于开发与维护.最近正在把逻辑很重的js拆分成模块,在一顿纠结是使用requirejs还 ...

  2. Jersey框架二:Jersey对JSON的支持

    Jersey系列文章: Jersey框架一:Jersey RESTful WebService框架简介 Jersey框架二:Jersey对JSON的支持 Jersey框架三:Jersey对HTTPS的 ...

  3. U8Linux磁盘与文件系统管理

    1.扇区为最小的物理存储单位,每个扇区为512bytes;将扇区组成一个圆,那就是柱面,柱面是分区的最小单位.Linux系统的EX2文件系统:inode的内容用于记录文件的权限与相关属性. 至于blo ...

  4. Codeforces Round #277.5 (Div. 2)---B. BerSU Ball (贪心)

    BerSU Ball time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  5. 学了Java 你未必知道这些

    作为一个正奔跑向编程完美天堂的朝圣者,本人觉得在平常的编程中,应该要做到以下几点: 一:汝应注释,这样做既方便别人,也方便自己去读懂代码的逻辑 二:注重细节,为自己写的每行代码负责,比如,在并发编程的 ...

  6. java反射中Method类invoke方法的使用方法

    package com.zsw.test; import java.lang.reflect.Method;import java.lang.reflect.InvocationTargetExcep ...

  7. Callable 获取线程返回值

    allable与 Future 两功能是Java在兴许版本号中为了适应多并法才增加的,Callable是类似于Runnable的接口,实现Callable接口的类和实现Runnable的类都是可被其它 ...

  8. cocos2dx的发展的例子2048(加入动画版)

    网上找了很多写作教程2048.只是不知道卡的移动动画,我写了一个完美的动画版少. 开发步骤: 1,一个设计CardSprite类. 2,设计主游戏场景GameScene,实现游戏逻辑,加入动画逻辑. ...

  9. Dreamer 3.0 支持json、xml、文件上传

    自己写的框架,功能类似Struts2.x 下载地址:http://pan.baidu.com/share/link?shareid=3273223286&uk=470382596 新增功能: ...

  10. ecshop2.7.3怎么自动清除缓存

    1.在ecs_shop_config表中插入一条数据 进入ECSHOP后台-数据库管理-SQL查询 复制下面SQL,粘贴到里面执行.注意这时是默认表前缀ecs_,如果你的修改过要和你的统一了. INS ...