UVA 11488 Hyper Prefix Sets (字典树)
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2483
组织一棵Trie 记录每个节点有多少串经过 统计最大值
由于只出现0,1,于是建立一个字典树,每一次到达一个节点,就在这个节点加上深度,然后ans求解最大的节点附加值就可以了。注意初始化
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <queue>
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 INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
#define maxnode 100000
typedef long long ll;
ll gcd(ll a,ll b){
return b?gcd(b,a%b):a;
}
bool cmp(int x,int y)
{
return x>y;
}
const int N=;
const int mod=1e9+;
int n;
struct Trie
{
int ch[maxnode][];
int val[maxnode];
int sz=,ans=;
void init(){sz=;
ans=;
memset(ch[],,sizeof(ch[]));
memset(val,,sizeof(val));
}
int idx(char c){
return c-'';
}
void insert(char* s,int len){
int u=;
for(int i=;i<len;i++){
int v=idx(s[i]);
if(!ch[u][v]){
memset(ch[sz],,sizeof(ch[sz]));
ch[u][v]=sz++;
}
u=ch[u][v];
val[u]+=(i+);
ans=max(ans,val[u]);
}
}
};
struct Trie trie;
char s[maxnode];
int main()
{
int t;
cin>>t;
while(t--){
trie.init();
cin>>n;
while(n--){
cin>>s;
trie.insert(s,strlen(s));
}
cout<<trie.ans<<"\n";
}
return ;
}
UVA 11488 Hyper Prefix Sets (字典树)的更多相关文章
- UVA 11488 Hyper Prefix Sets (字典树)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- 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(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 ...
随机推荐
- css自动换行如何设置?url太长会撑开页面
我们更新文章时如果有引用其他文章一般会带一个原文url,但这个链接如果太长的话会把内容的版块撑开,整个排版乱了.那我们能不能设置css自动换行呢?如下图所示,其实只要两个样式就能搞定 word-wra ...
- dxRatingControl使用
Properties AllowHover:是否鼠标滑动选择 CheckedGlyph:选中后显示的图像 Glyph:显示的图像 HoverGlyph:鼠标滑动时显示的图像 ItemCount:项目总 ...
- JS中函数表达式与函数声明的区别
hello,沐晴又来更新啦,今天呢,跟大家讲讲让人头疼的函数表达式和函数声明,反正我当初看那本高级程序的时候,是没怎么看太透,哈哈.我是个比较重基础的人,跟我一起探讨函数表达式和函数声明的世界吧. 首 ...
- vue-3.0创建项目
.npm install --global @vue/cli .npm install -g @vue/cli-init .vue init webpack my-project
- C 字符及ASCII值
.已知字母A的ASCII码为十进制的65,下面程序的输出是___A___. main() { char ch1,ch2; ch1='; ch2='; printf("%d,%c\n" ...
- 2019.03.18 连接my sql
11.登陆功能(链接MySQL) python manage.py starapp movie 新建一个应用模块之后要记得到setting添加这个应用模块 在python2中你还有去导入一个MySQL ...
- jenkins 常用插件和配置项介绍和使用
jenkins 上搜索不到的插件可以在如下地址下载: http://updates.jenkins-ci.org/download/plugins/ 1.Notification Plugin 介绍: ...
- Elasticsearch5.x批量插入数据(Java)
先上官方示例代码:官方示例 Java代码: // 批量插入数据 public void InsertBatch() { try { // 设置集群名称 Settings settings = Sett ...
- python 参数解析ArgumentParser
#!/usr/bin/env python #coding:utf-8 from argparse import ArgumentParser #--------------------------- ...
- MongoDB Driver:使用正确的姿势连接复制集
from:https://yq.aliyun.com/articles/8461?spm=5176.7937264.222114.10.s2oqcT 摘要: MongoDB复制集(Replica ...