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

给定一个字符串集合S, 定义P(S)为所有字符串的公共前缀长度与S中字符串个数的乘积, 例如P{000, 001, 0011} = 6,

现在给出n个只包含字符01的串(n <= 50000), 从中选出一个子集合S, 使得P(S)最大, 求最大值

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define ios() ios::sync_with_stdio(false)
#define INF 0x3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
char s[];
int ans,n,t,pos;
struct Trie
{
int next[];
int cnt;
void init()
{
cnt=;
memset(next,,sizeof(next));
}
}trie[];
void init()
{
for(int i=;i<=n*;i++ )
{
trie[i].init();
}
}
void insert(char *s)
{
int x=;
for(int i=;s[i]!='\0';i++)
{
if(trie[x].next[s[i]-'']==)
{
trie[x].next[s[i]-'']=++pos;
trie[pos].init();
}
x=trie[x].next[s[i]-''];
trie[x].cnt++;
ans=max(ans,(i+)*trie[x].cnt);
}
}
int main()
{
scanf("%d",&t);
while(t--)
{ ans=,pos=;
scanf("%d",&n);
init();
for(int i=;i<n;++i)
{
scanf("%s",s);
insert(s);
}
printf("%d\n",ans); }
return ;
}

UVA 11488 Hyper Prefix Sets (字典树)的更多相关文章

  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)

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

  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树)

    1.给n个只含0.1的串,求出这些串中前缀的最大和. 例1: 0000 0001 10101 010 结果:6(第1.2串共有000,3+3=6) 例2: 01010010101010101010 1 ...

  5. UVa 11488 - Hyper Prefix Sets

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

  6. uva 11488 Hyper Prefix Sets(狂水)

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

  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. 208 Implement Trie (Prefix Tree) 字典树(前缀树)

    实现一个 Trie (前缀树),包含 insert, search, 和 startsWith 这三个方法.注意:你可以假设所有的输入都是小写字母 a-z.详见:https://leetcode.co ...

  9. 【leetcode】208. Implement Trie (Prefix Tree 字典树)

    A trie (pronounced as "try") or prefix tree is a tree data structure used to efficiently s ...

随机推荐

  1. C++ priority_queue的使用 & Java PriorityQueue

    刚刚那道BST的题目,也用到了priority_queue,那是那个没有定义比较函数. 那么下面这个,就要定义比较函数. 它的模板声明带有三个参数,priority_queue<Type, Co ...

  2. Equals和==比較

    总结一下: 对于字符串来说.两个比較的都是对象的值,而且是等效的,这是由于MS重写了==运算符和Equals方法所致             对于非字符串的其它引用类型(非匿名类型)两个比較的都是对象 ...

  3. vue3事件

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. Lesson 2 Building your first web page: Part 2

    Tag Diagram You may have noticed that HTML tags come in pairs; HTML has both an opening tag (<tag ...

  5. 解决Maven项目相互依赖/循环依赖/双向依赖的问题

    转自:https://blog.csdn.net/leolu007/article/details/53079875 添加新随笔很​多​时​候​随​着​项​目​的​膨​胀​,模​块​会​越​来​越​多 ...

  6. IBM软件技术峰会归来

    为期两天在北京国际饭店会议中心的IBM软件技术峰会已近结束,此次大会最大的收获是能和沃森实验室的王博士沟通探讨人工智能软件的发展问题.领略到IBM 云计算首席架构师Jason R.McGee如何呼风唤 ...

  7. POSTGRESQL NO TABLE

    POSTGRESQL EXTENDING SQL GRIGGER PROCEDURAL

  8. hight charts

    hight charts http://www.hcharts.cn/resource/index.php http://www.hcharts.cn/api/index.php

  9. Coderfroces 862 C. Mahmoud and Ehab and the xor

    C. Mahmoud and Ehab and the xor Mahmoud and Ehab are on the third stage of their adventures now. As ...

  10. 推荐《深入浅出深度学习原理剖析与python实践》PDF+代码

    <深入浅出深度学习原理剖析与Python实践>介绍了深度学习相关的原理与应用,全书共分为三大部分,第一部分主要回顾了深度学习的发展历史,以及Theano的使用:第二部分详细讲解了与深度学习 ...