UVA - 11488 前缀
题目链接: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 前缀的更多相关文章
- UVa 11488 超级前缀集合(Trie的应用)
https://vjudge.net/problem/UVA-11488 题意: 给定一个字符串集合S,定义P(s)为所有字符串的公共前缀长度与S中字符串个数的乘积.比如P( {000, 001, 0 ...
- UVA - 11488 字典树
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- 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(狂水)
题意: 获得集合中最长前缀长度*有该前缀个数的最大值 Prefix goodness of a set string is length of longest common prefix*number ...
- UVa 11488 - Hyper Prefix Sets
找 前缀长度*符合该前缀的字符串数 的最大值 顺便练了一下字典树的模板 #include <iostream> #include <cstdio> #include <c ...
- 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(字典树)
H Hyper Prefix Sets Prefix goodness of a set string is length of longest common prefix*number of str ...
随机推荐
- MongoDB复杂查询语句记录
前段时间做业务监控,用到了MongoDB,有一个查询是把一个含array的list里面查询array中是否存在某一对unique值,不存在的情况下插入一条记录. 类似这样一个表: Biao{ id, ...
- Blockly
Blockly简介 A library for building visual programming editors. Blockly 是个库,可用来构建可视化编程编辑器 Blockly is b ...
- Gradle发布项目到 maven 之gradle-bintray-plugin(2)
上传的方式有两种,第一种是通过 bintray 官方出的插件 bintray/gradle-bintray-plugin 第二种是一个国外组织开源的插件 novoda/bintray-release ...
- oracle OEM安装(一)
01,用户解锁添加密码 [oracle@oracle01 ~]$ sqlplus / as sysdba SQL Production :: Copyright (c) , , Oracle. All ...
- MySQL误删root用户导致无法登陆解决方法
测试环境 删除前 mysql> select user,host,password from mysql.user; +------+-----------+---------------- ...
- linux 入门测验
cd . 当前目录.. 返回上一级目录 ../../../返回多级目录 grep "目标信息" 目标地址 -v :显示没有被匹配的信息 mkdir -p:创建多级目录 mkdir ...
- python-URL转jpg图片
问题描述 有图片地址,可以在网页打开 URL:https://bdfile.bluemoon.com.cn/group2/M00/0A/BA/wKg_HlwzY1SAIdXDAAFyo-ZOLKQ39 ...
- Unable to connect to data source (DSN: shangjihuiclient; Network Address: ; Port Number: 53397). Cannot connect to TimesTen Server. Verify that the TimesTen Server is running or verify that your TCP PORT is set correctly.
安装完毕TimesTen后,在客户端连接时一直报错. 解决办法是:重启服务器,在连接没在报这个错误.
- android AIDL服务
这篇文章http://byandby.iteye.com/blog/1026110我们介绍了android的本地服务:它只能由承载它的应用程序使用.现在我们将介绍如何构建可由其他进程通过 RPC 使用 ...
- 网络连接和初始HTTP请求
浏览器检索网页,先从URL开始,使用DNS确定IP地址,再用基于TCP和HTTP协议连接到服务器,请求相关的内容,得到相应,浏览器解析并呈现到屏幕上.服务器响应后,浏览器响应不会同时全部到达,会陆续到 ...