https://vjudge.net/problem/UVA-11488 题意: 给定一个字符串集合S,定义P(s)为所有字符串的公共前缀长度与S中字符串个数的乘积.比如P( {000, 001, 0011} ) = 6.给n个01串,从中选择一个集合S,使得P(S)最大. 思路: 建立字典树,边插入边统计答案即可. 用两个变量分别记录前缀数量和前缀长度,每次插入时动态更新两者乘积. #include<iostream> #include<cstdio> #include<c…
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2483 Hyper Prefix Sets Prefix goodness of a set string islength of longest common prefix*number of strings in the set.For example the prefix goodnes…
前缀树Trie Trie可理解为一个能够快速插入与查询的集合,无论是插入还是查询所需时间都为O(m) 模板如下: +; ; struct Trie{ int ch[maxnode][sigma_size]; int val[maxnode]; int sz; ; memset(ch[],,])); } int ID(char c){ return c='a'; }; void insert(char* s,int v){ //向Trie中插入 , n=strlen(s); ;i<n;i++) {…
题意:给定strcmp函数,输入n个字符串,让你用给定的strcmp函数判断字符比较了多少次. 析:题意不理解的可以阅读原题https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2832 字符串很多,又很长,如果按照题目的意思两两比较,肯定会TLE,所以要用前缀树(Trie)来解决,当然只是用简单的前缀树也会TLE的, 我们必须对其进行优化,看了…
题目链接:https://vjudge.net/contest/166647#problem/A 题意: 从一些字符串集合里面挑一子集,然后公共前缀长度*字符串个数最大: 分析: 将这些字符串放到一个字典树中,每个节点作为公共前缀(长度)*个数(边插入,边累加) #include <bits/stdc++.h> using namespace std; +)*; struct Trie { ]; int val[maxnode]; int sz; int ans; void init () {…
1.给n个只含0.1的串,求出这些串中前缀的最大和. 例1: 0000 0001 10101 010 结果:6(第1.2串共有000,3+3=6) 例2: 01010010101010101010 11010010101010101010 结果:20(第1串的长度为20) 2.用trie树(字典树)来做,插入的时候统计前缀出现次数,并更新最大前缀和(前缀出现次数*前缀长度). 3. #include<iostream> #include<stdio.h> #include<s…
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 <i…
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2483 题意:给定一堆由0,1组成的串,现在要求一个最大值,值的结果为:串前缀*用于此前缀的字符串个数 思路:字典树,在插入字符串的时候就开始统计,对于插入的每个字符串的前缀的值都累加,然后一边插入一边维护最大值即可. #define _CRT_SECURE_NO_DEPRECAT…
题意: 获得集合中最长前缀长度*有该前缀个数的最大值 Prefix goodness of a set string is length of longest common prefix*number of strings in the set. For example the prefix goodness of the set {000,001,0011} is 6.You are given a set of binary strings. Find the maximum prefix…
题意: 给一个01串的集合,一个集合的幸运值是串的个数*集合中串的最大公共前缀 ,求所有子集中最大幸运值 分析: val[N]表示经过每个节点串的个数求幸运值 求就是每个节点值*该节点的深度 搜一遍树求出最大值 #include <map> #include <set> #include <list> #include <cmath> #include <queue> #include <stack> #include <cst…