题目链接: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. linux 登陆失败处理

    1.备份要操作的两个配置文件 cp /etc/pam.d/sshd /etc/pam.d/sshd.bak cp /etc/pam.d/login /etc/pam.d/login.bak 2.检查是 ...

  2. (转)裸奔的后果!一次ssh被篡改的入侵事件

    裸奔的后果!一次ssh被篡改的入侵事件 原文:http://blog.51cto.com/phenixikki/1546669 通常服务器安全问题在规模较小的公司常常被忽略,没有负责安全的专员,尤其是 ...

  3. (转)2017年最新企业面试题之shell(一,二)

    2017年最新企业面试题之shell(一) ********************************************** 企业Shell面试题1:批量生成随机字符文件名案例 * *** ...

  4. 常用css搜集

    div居中显示 position: fixed; top: 130px; left:0px;right:0px;margin-left:auto;margin-right:auto;

  5. TOJ 2452 Ultra-QuickSort

    描述 In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a se ...

  6. linux_api之进程环境

    本篇索引: 1.引言 2.main函数 3.进程的终止方式 4.exit和_exit函数 5.atexit函数 7.环境表 8.C程序程序空间布局 9.存储空间的手动分配 10.库文件 1.引言 一个 ...

  7. Nginx实践:(2) Nginx语法之localtion

    1. 概念 location是根据uri进行不同的定位.在虚拟主机的配置中,是必不可少的.location可以将网站的不同部分,定位到不同的处理方式上. location语法格式如下: locatio ...

  8. Win10内置应用恢复初始状态

    和Win8/Win8.1相同,Win10也内置了很多默认Windows应用,比如计算器.天气.人脉.Groove音乐.电影和电视.邮件和日历.Edge浏览器等.一般情况下,这些应用不会有太大的问题,但 ...

  9. 中文输入法无法在 QtCreator(Linux) 中输入汉字

    中文输入法无法在 QtCreator(Linux) 中输入汉字 环境 system: Deepin 15.7 Qt Creator 4.7.0 (GCC 5.3.1) 解决方法 下载 fcitx-qt ...

  10. MVC中提交表单的4种方式

    一,MVC  HtmlHelper方法 Html.BeginForm(actionName,controllerName,method,htmlAttributes){} BeginRouteForm ...