找 前缀长度*符合该前缀的字符串数 的最大值

顺便练了一下字典树的模板

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;
struct trie{
trie *next[];
int index;//数量
};
inline trie* newnode()
{
trie *t;
t=(trie*)malloc(sizeof(trie));
memset(t,,sizeof(trie));// !!!!!
return t;
}
int t,n,ans;
char s[];
void insert(trie *s,char x[])
{
int i,k;
trie *t;
for(i=;x[i];i++)
{
k=x[i]-'';
if(s->next[k])s=s->next[k];
else{
t=newnode();
s->next[k]=t;
s=t;
}
s->index++;
}
}
void find(trie *s,int x)
{
int i,k;
for(i=;i<;i++)
{
if(s->next[i]){
ans=max(ans,s->next[i]->index*x);
find(s->next[i],x+);//向下找
}
}
}
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
trie* root=newnode();
for(int i=;i<=n;++i)
{
scanf("%s",s);
insert(root,s);
}
ans=;
find(root,);
printf("%d\n",ans);
}
}

UVa 11488 - Hyper Prefix Sets的更多相关文章

  1. UVA 11488 Hyper Prefix Sets (Trie)

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

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

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

  3. uva 11488 Hyper Prefix Sets(狂水)

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

  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 (字典树)

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

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

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

  8. Hyper Prefix Sets

    uva11488:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&am ...

  9. UVa11488-Hyper Prefix Sets(trie树)

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

随机推荐

  1. HDU 5735 - Born Slippy

    题意: 一棵 n 个节点的根树,i 节点权重 wi 对每一个节点s,找到这样一个长 m 的标号序列 v : 1. vi是vi-1 的祖先 2. f[s] = w[vi] + ∑(i=2, m) (w[ ...

  2. 一个数n的最大质因子

    #include<cstdio> #include<cmath> using namespace std; #define Max(x, y) (x > y ? x : ...

  3. (原+转)C++中的lambda表达式

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5073376.html 参考网址: http://www.cnblogs.com/zhuyp1015/a ...

  4. js跨浏览器事件处理

    var EventUtil = { addHandler: function(element,type,handler){ if(element.addEventListener){ element. ...

  5. Lucene学习总结之二:Lucene的总体架构

    Lucene总的来说是: 一个高效的,可扩展的,全文检索库. 全部用Java实现,无须配置. 仅支持纯文本文件的索引(Indexing)和搜索(Search). 不负责由其他格式的文件抽取纯文本文件, ...

  6. select2使用详解

    官网: https://select2.github.io/examples.html 引用: <link href="~/Scripts/select2/select2.css&qu ...

  7. vmware9安装centos和Mac经验总结

    其实以前安装过,但是这次安装发现还是很陌生 主要是因为以下几点vm11下载的最新版本结果不支持用vm-Mac激活包一直激活不成功,所以只好用vm9来进行,中间的细节操作就是要停止的那几项VMware服 ...

  8. 欧拉(BC)

    输入样例 1 1 2 1 3 2 输出样例 2 2 2f(x)打表找规律的 fx=x+1,fn(x)=x+n+1;然后用欧拉公式 #include <iostream> #include ...

  9. [转]浅谈C/C++内存泄露及其检测工具

    转自:http://www.cnblogs.com/taoxu0903/archive/2007/10/27/939261.html 对于一个c/c++程序员来说,内存泄漏是一个常见的也是令人头疼的问 ...

  10. 利用raspberry pi搭建typecho笔记(二) sqlite和typecho部署

    sqlite概述 typecho可以支持MYSQL和Sqlite两种数据库,因为Sqlite更为轻量,并且不需要额外的进程,而是直接对数据库文件进行读取,所以配置相对于MySQL也更为简单,仅需指定数 ...