题意:

给一个01串的集合,一个集合的幸运值是串的个数*集合中串的最大公共前缀 ,求所有子集中最大幸运值

分析:

val[N]表示经过每个节点串的个数求幸运值 求就是每个节点值*该节点的深度 搜一遍树求出最大值
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int>P;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define N 10000010
#define read freopen("in.txt", "r", stdin)
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = ;
struct Trie{
int ch[N][];
int val[N],num;
void init(){
num=;
memset(ch[],,sizeof(ch[]));
memset(val,,sizeof(val));
}
//建树
void build(char *s){
int u=,len=strlen(s);
for(int i=;i<len;++i){
int v=s[i]-'';
if(!ch[u][v]){
memset(ch[num],,sizeof(ch[num]));
ch[u][v]=num++;
}
u=ch[u][v];
val[u]++;
}
}
//bfs
ll query(){
queue<P>q;
ll maxv=;
q.push(P(,));
while(!q.empty()){
P p=q.front();
q.pop();
int u=p.first;
int h=p.second;
maxv=max(maxv,1LL*val[u]*h);
for(int i=;i<;++i){
if(ch[u][i]){
q.push(P(ch[u][i],h+));
}
}
}
return maxv;
}
}trie;
int main()
{
int t,n;
char str[];
scanf("%d",&t);
for(int o=;o<t;++o){
trie.init();
scanf("%d",&n);
for(int i=;i<n;++i){
scanf("%s",str);
trie.build(str);
}
printf("%lld\n",trie.query());
}
return ;
}
 

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

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

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

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

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

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

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

  6. UVA 11488 Hyper Prefix Sets (Trie)

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

  7. uva 11488 Hyper Prefix Sets(狂水)

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

  8. UVa 11488 - Hyper Prefix Sets

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

  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. Android导入Cocos2D的Sample项目

    导入Cocos2D项目到Android的Eclipse时注意以下几点 1. Set up Variables: Eclipse->Windows->Preferences->Gene ...

  2. VS2008的默认打开重置为VS2008

  3. [Windows Azure] Querying Tables and Entities

    Constructing Filter Strings When constructing a filter string, keep these rules in mind: Use the log ...

  4. 同一台Windows机器中启动多个Memcached服务

    同一台Windows机器中启动多个Memcached服务 这就需要在一台机器上启动多个Memcached服务了. 假设Memcached在如下目录:C:\memcached\memcached.exe ...

  5. What is an eigenvector of a covariance matrix?

    What is an eigenvector of a covariance matrix? One of the most intuitive explanations of eigenvector ...

  6. gcc: error trying to exec 'cc1plus': execvp: 没有该文件或目录 解决方案

    一般来说,装完linux系统(ubuntu)后,要自己安装java或者c/c++的环境. 这个提示就是说你的系统缺少 g++ 包. 请执行:sudo apt-get install g++  (在ub ...

  7. 深入理解ClassLoader(五)—类的卸载

    原文地址:http://yhjhappy234.blog.163.com/blog/static/316328322011101413730764/?suggestedreading&wumi ...

  8. linux 2.6 互斥锁的实现-源码分析

    http://blog.csdn.net/tq02h2a/article/details/4317211 看了看linux 2.6 kernel的源码,下面结合代码来分析一下在X86体系结构下,互斥锁 ...

  9. Android安全问题 程序锁

    导读:本文介绍如何实现对应用加锁的功能,无须root权限 某些人有时候会有这样一种需求,小A下载了个软件,只是软件中的美女过于诱惑与暴露,所以他不想让别人知道这是个什么软件,起码不想让别人打开浏 览. ...

  10. mmap

    http://www.360doc.com/content/11/0830/10/1964482_144428042.shtml