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. vue工厂化完整项目目录

  2. Spring全局异常捕获

    package org.xxx.ac.zpk.exception; import java.io.IOException; import javax.servlet.http.HttpServletR ...

  3. opencv读图片错误,已解决

    could not loag image... terminate called after throwing an instance of 'cv::Exception' what(): OpenC ...

  4. Python应该怎样实现快速入门?

    作为一名Python爱好者,我也想跟大家分享分享我自学Python的一些小经验.搬来你的小板凳,听听看吧.也许,你会很有收获,也许你也走上了自学Python的不归路.开讲啦~ 首先,你要有自信心,要明 ...

  5. Android实战简易教程-第四十九枪(两种方式实现网络图片异步加载)

    加载图片属于比较耗时的工作,我们需要异步进行加载,异步加载有两种方式:1.通过AsyncTask类进行:2.通过Handler来实现,下面我们就来看一下如何通过这两种方式实现网络图片的异步加载. 一. ...

  6. 【转】WinAPI: CreateFontIndirect - 根据字体结构建立逻辑字体

    //声明: CreateFontIndirect( const p1: TLogFont {字体结构} ): HFONT; {返回新字体指针} //TLogFont 是 tagLOGFONTA 结构的 ...

  7. python3.x Day6 多线程

    线程???进程????区别???何时使用??? 进程:是程序以一个整体的形式暴露给操作系统管理,里边包含了对各种资源的调用,内存的使用,对各种资源的管理的集合,这就叫进程 线程:是操作系统最小的调度单 ...

  8. JS 根据参数是否为空进行true|false判断呢

    <form id="actForm" action="${ctx}/meeting/vip/saveMeetingAttendVipAct" method ...

  9. Leetcode 166.分数到小数

    分数到小数 给定两个整数,分别表示分数的分子 numerator 和分母 denominator,以字符串形式返回小数. 如果小数部分为循环小数,则将循环的部分括在括号内. 示例 1: 输入: num ...

  10. MySQL最优配置文件模板·2016-11-28

    小伙伴们大爱的MySQL最优配置文件模板更新啦.对之前的MySQL最优配置文件·20160901做了一些修正,更为名至实归.可以通过此链接进行下载.当然,更欢迎同学们提出意见和建议,共同打造一个最优M ...