UVA 11488 Hyper Prefix Sets (字典树)
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 (字典树)的更多相关文章
- uva 11488 - Hyper Prefix Sets(字典树)
H Hyper Prefix Sets Prefix goodness of a set string is length of longest common prefix*number of str ...
- UVA 11488 Hyper Prefix Sets (Trie)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- UVA 11488 Hyper Prefix Sets (字典树)
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- 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 ...
- UVa 11488 - Hyper Prefix Sets
找 前缀长度*符合该前缀的字符串数 的最大值 顺便练了一下字典树的模板 #include <iostream> #include <cstdio> #include <c ...
- uva 11488 Hyper Prefix Sets(狂水)
题意: 获得集合中最长前缀长度*有该前缀个数的最大值 Prefix goodness of a set string is length of longest common prefix*number ...
- 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 ...
- 208 Implement Trie (Prefix Tree) 字典树(前缀树)
实现一个 Trie (前缀树),包含 insert, search, 和 startsWith 这三个方法.注意:你可以假设所有的输入都是小写字母 a-z.详见:https://leetcode.co ...
- 【leetcode】208. Implement Trie (Prefix Tree 字典树)
A trie (pronounced as "try") or prefix tree is a tree data structure used to efficiently s ...
随机推荐
- 从零開始学android<SlidingDrawer 隐式抽屉.三十三.>
SlidingDrawer是一种抽屉型的组件.当用户选择打开此抽屉之后,会得到一些能够使用的"程序集".这样当一个界面要摆放多个组件的时候,使用此组件就能够非常好的解决布局空间紧张 ...
- ORA-01003: no statement parsed
环境:delphi 5.BDE.oracle10 delphi里面用tStoreProc调用存储过程出现ORA-01003: no statement parsed. 解决方法:tStoreProc. ...
- Qt creator 编译错误 :cannot find file .pro qt
事实上问题的解决的方法非常easy:就是Qt不支持中文的路径,把源代码的路径所有改成英文就可以解决这个问题. 首先问题发生在我执行网上的样例程序时,又一次构建编译也是出错.提示: Cannot fin ...
- centos7 keepalive双机热备~
简单实现Keepalive双击热备~ 摘要:准备两台虚拟机A:192.168.161.7 B:192.168.161.35 虚拟ip:192.168.161.10 keepalive进程 具体关于 ...
- JavaScript 与Document
JavaScript JavaScript 是脚本语言, 需要有宿主文件, 他的宿主文件是HTML文件. 可以写在head中 body中 和</heml>之后 一般写在< ...
- js实现导出数据到excel
来自:http://www.imooc.com/article/13374 //html代码<!DOCTYPE HTML> <html> <head> <ti ...
- Vue数据驱动表单渲染,轻松搞定form表单
form-create 具有动态渲染.数据收集.校验和提交功能的表单生成器,支持双向数据绑定.事件扩展以及自定义组件,可快速生成包含有省市区三级联动.时间选择.日期选择等17种功能组件. Github ...
- 实现人脸识别性别之路---opencv
import cv2from make_imge import get_file_namefrom train_ph import Modelimport os IMAGE_SIZE = 128if ...
- 2017-2018年红头发新版Cisco认证网络工程师(CCNA-R&S)全新讲解分享
网名"红头发",多年授课经验,业内资深思科认证讲师,其所写的CISCO认证原创技术文章风靡各大网站与培训机构.精通CISCO各类路由交换产品,熟悉JUNIPER M/T系列路由产品 ...
- 使用 HTML5 canvas制作拾色器
自制的拾色器漂亮吧,哈哈 废话不多说直接上代码,希望可以帮到需要的朋友 <html><head> <style> .canvas_color{p ...