题目链接:https://vjudge.net/contest/166647#problem/A

题意:

从一些字符串集合里面挑一子集,然后公共前缀长度*字符串个数最大;

分析:

将这些字符串放到一个字典树中,每个节点作为公共前缀(长度)*个数(边插入,边累加)

 #include <bits/stdc++.h>

 using namespace std;

 const int maxnode = (+)*;
struct Trie {
int ch[maxnode][];
int val[maxnode];
int sz;
int ans;
void init () {
ans = ;
sz = ;
memset(ch[],,sizeof(ch[]));
memset(val,,sizeof(val));
}
int idx(char c) {
return c - '';
} void insert(char *s,int v) {
int u = ,n = strlen(s);
for(int i=;i<n;i++) {
int c = idx(s[i]);
if(ch[u][c]==) {
memset(ch[sz],,sizeof(ch[sz]));
ch[u][c] = sz++;
}
u = ch[u][c];
val[u] +=(i+);
ans = max(ans,val[u]);
}
} }sol; char str[]; int main()
{
int t;
scanf("%d",&t);
while(t--) {
int n;
sol.init();
scanf("%d",&n);
for(int i=;i<n;i++) {
scanf("%s",str);
sol.insert(str,);
} printf("%d\n",sol.ans);
}
return ;
}

UVA - 11488 前缀的更多相关文章

  1. UVa 11488 超级前缀集合(Trie的应用)

    https://vjudge.net/problem/UVA-11488 题意: 给定一个字符串集合S,定义P(s)为所有字符串的公共前缀长度与S中字符串个数的乘积.比如P( {000, 001, 0 ...

  2. UVA - 11488 字典树

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

  3. UVA 11488 Hyper Prefix Sets (Trie)

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

  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(狂水)

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

  6. UVa 11488 - Hyper Prefix Sets

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

  7. UVA 11488 Hyper Prefix Sets (字典树)

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

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

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

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

随机推荐

  1. vue-watch deep 和 immediate

    watch 是一个对象,对象就有键,有值. 值可以是函数:就是当你监控的家伙变化时,需要执行的函数,这个函数有两个形参,第一个是变化后的值,第二个是变化前的值. 值也可以是函数名:不过这个函数名要用单 ...

  2. Oracle RAC集群搭建(末篇)--dbca建库

    一,环境配置检测 当前位置oracle用户 二,dbca建库 运行命令dbca 根据实际情况配置 等待完成 本次内容教程完成 查看IP信息

  3. linux运维之top命令

    统计信息区前五行是系统整体的统计信息: 第一行是任务队列信息,同 uptime  命令的执行结果.其内容如下: 01:06:48 当前时间 up 1:22 系统运行时间,格式为时:分 1 user 当 ...

  4. 4GLTE@NB-IOT

    参考:https://www.cnblogs.com/pangguoming/p/9755916.html NB-IOT特点:在4G基础上发展而来,覆盖广,海量接入,成本低低功耗:不适合应用情况:大数 ...

  5. myeclipse更改后台代码不用重启tomcat的方法

    myeclipse更改后台代码不用重启tomcat的方法   方法1:在WebRoot下的META-INF文件夹中新建一个名为context.xml文件,里面添加如下内容(要区分大小写): <C ...

  6. (转)Linux 系统性能分析工具图解读(一、二)

    Linux 系统性能分析工具图解读(一.二) 原文:http://oilbeater.com/linux/2014/09/08/linux-performance-tools.html 最近看了 Br ...

  7. HDU 4460 Friend Chains

    Problem Description For a group of people, there is an idea that everyone is equals to or less than ...

  8. 【转】常用的邮箱服务器(SMTP、POP3)地址、端口

    gmail(google.com)POP3服务器地址:pop.gmail.com(SSL启用 端口:995)SMTP服务器地址:smtp.gmail.com(SSL启用 端口:587) 21cn.co ...

  9. Nginx下载安装

    系统环境:win7 nginx:1.11.4 1.下载Nginx 下载地址:http://nginx.org/en/download.html 2.将压缩包解压到相应位置 3.启动nginx服务,ng ...

  10. oracle OTT 学习

    1.OTT概念 OTT 是 Object Type Translator 的缩写,对象类型转换器.它是用来将数据库中定义的类型(UDT)转换为C结构体类型的工具.借助OTT 可以用C语言调用OCI来访 ...