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

Hyper Prefix Sets

Prefix goodness of a set string islength of longest common prefix*number of strings in the set.For example the prefix goodness of theset {000,001,0011} is 6.You are given a set of binarystrings. Find the maximum prefixgoodness 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 withn(≤50000) the number of strings. Eachof the next n lines contains a string containing only 0 andMaximum length of each of thesestring
is 200.

Output

For each test case output the maximumprefix goodness among all possible subsets of n binarystrings.

Sample Input

4

4

0000

0001

10101

010

2

01010010101010101010

11010010101010101010

3

010101010101000010001010

010101010101000010001000

010101010101000010001010

5

01010101010100001010010010100101

01010101010100001010011010101010

00001010101010110101

0001010101011010101

00010101010101001

Output for Sample Input

6

20

66

44

Problem Setter : Abdullah Al Mahmud

Special Thanks : Manzurur Rahman Khan

题意:

给出N个字符串,要求选出若干个,使得选中的字符串的公共前缀长度与选中字符串的个数的乘积最大。

分析:

简单粗暴的Trie模板题。

对于Tire中的每个结点加入两个信息:该结点的深度及该结点杯訪问的次数。最后求出这两个信息的最大值即可了,边加入字符串边维护即可。

/*
*
* Author : fcbruce
*
* Time : Sat 04 Oct 2014 09:17:50 PM CST
*
*/
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <algorithm>
#include <ctime>
#include <cctype>
#include <cmath>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>
#define sqr(x) ((x)*(x))
#define LL long long
#define itn int
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626
#define eps 1e-10 #ifdef _WIN32
#define lld "%I64d"
#else
#define lld "%lld"
#endif #define maxm 2
#define maxn 5000007 using namespace std; struct Trie
{
int ch[maxn][maxm];
int deep[maxn];
int cnt[maxn][maxm];
int MAX;
int sz; Trie()
{
sz=1;
deep[0]=0;
MAX=0;
memset(cnt[0],0,sizeof cnt[0]);
memset(ch[0],0,sizeof ch[0]);
} void clear()
{
sz=1;
deep[0]=0;
MAX=0;
memset(cnt[0],0,sizeof cnt[0]);
memset(ch[0],0,sizeof ch[0]);
} int idx(const char ch)
{
return ch-'0';
} void insert(const char *s)
{
for (int i=0,j=0;s[i]!='\0';i++)
{
int c=idx(s[i]);
if (ch[j][c]==0)
{
memset(ch[sz],0,sizeof ch[sz]);
memset(cnt[sz],0,sizeof cnt[sz]);
deep[sz]=i+1;
ch[j][c]=sz++;
}
j=ch[j][c];
cnt[j][c]++;
MAX=max(MAX,deep[j]*cnt[j][c]);
}
}
}trie; char str[233]; int main()
{
#ifdef FCBRUCE
freopen("/home/fcbruce/code/t","r",stdin);
#endif // FCBRUCE int T_T;
scanf("%d",&T_T); while (T_T--)
{
trie.clear(); int n;
scanf("%d",&n); for (int i=0;i<n;i++)
{
scanf("%s",str);
trie.insert(str);
} printf("%d\n",trie.MAX);
} return 0;
}

UVA 11488 Hyper Prefix Sets (Trie)的更多相关文章

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

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

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

  3. uva 11488 Hyper Prefix Sets(狂水)

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

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

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

  6. UVa 11488 - Hyper Prefix Sets

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

  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. java_线程的通信

    线程的通信共有三个方法: wait()运行时阻塞,释放锁 notify()唤醒阻塞线程 notifll()唤醒全部阻塞线程 public class ThreadTest01 { public sta ...

  2. 【计算机网络】2.2 Web和HTTP

    第二章第二节 Web和HTTP 这一章中,我们需要讨论5种重要的应用:Web.文件传输.电子邮件.目录服务.P2P:这一节中,我们将讨论Web和它的应用层协议HTTP. Outline Web简介 H ...

  3. CentOS 初体验十四:阿里云安装Gitlab

    网址:https://about.gitlab.com/install/#centos-7 https://blog.csdn.net/zhaoyanjun6/article/details/7914 ...

  4. vue 改变插值方法

    Vue默认的插值是双大括号{{}}.但有时我们会有需求更改这个插值的形式. delimiters:['${','}']  //必须要用一个数组来接收,用逗号隔开.

  5. struct 和class 区别

    最开始,就让我们来讨论一下一个最最基本,也最最容易被人忽视掉的问题——C++中的struct和class有什么区别?如果谈到C中的struct和C++中的class的区别,你应该会告诉我很多.但我现在 ...

  6. 笔试算法题(24):找出出现次数超过一半的元素 & 二叉树最近公共父节点

    出题:数组中有一个数字出现的次数超过了数组长度的一半,请找出这个数字: 分析: 解法1:首先对数组进行排序,时间复杂度为O(NlogN),由于有一个数字出现次数超过了数组的一半,所以如果二分数组的话, ...

  7. scrapy实现全站抓取数据

    1. scrapy.CrawlSpider scrapy框架提供了多种类型的spider,大致分为两类,一类为基本spider(scrapy.Spider),另一类为通用spider(scrapy.s ...

  8. 集训第六周 数学概念与方法 UVA 11722 几何概型

    ---恢复内容开始--- http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=31471 题意,两辆火车,分别会在[t1,t2],[ ...

  9. bzoj3262陌上花开 cdq分治入门题

    Description 有n朵花,每朵花有三个属性:花形(s).颜色(c).气味(m),又三个整数表示.现要对每朵花评级,一朵花的级别是它拥有的美丽能超过的花的数量.定义一朵花A比另一朵花B要美丽,当 ...

  10. <vue>…… v-if 与 v-show ……//

    #v-if 用法: 根据表达式的值的真假条件渲染元素.在切换时元素及它的数据绑定 / 组件被销毁并重建.如果元素是 <template> ,将提出它的内容作为条件块. 当条件变化时该指令触 ...