UVa 11488 - Hyper Prefix Sets
找 前缀长度*符合该前缀的字符串数 的最大值
顺便练了一下字典树的模板
#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的更多相关文章
- 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(字典树)
H Hyper Prefix Sets Prefix goodness of a set string is length of longest common prefix*number of str ...
- uva 11488 Hyper Prefix Sets(狂水)
题意: 获得集合中最长前缀长度*有该前缀个数的最大值 Prefix goodness of a set string is length of longest common prefix*number ...
- UVA 11488 Hyper Prefix Sets (字典树)
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- 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 ...
- 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 ...
- Hyper Prefix Sets
uva11488:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&am ...
- UVa11488-Hyper Prefix Sets(trie树)
H Hyper Prefix Sets Prefix goodness of a set string is length of longest common prefix*number of str ...
随机推荐
- iOS开发 XML解析和下拉刷新,上拉加载更多
iOS开发 XML解析和下拉刷新,上拉加载更多 1.XML格式 <?xml version="1.0" encoding="utf-8" ?> 表示 ...
- codeforces432D Prefixes and Suffixes(kmp+dp)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud D. Prefixes and Suffixes You have a strin ...
- spring 上传图片
@RequestMapping(value = "/upload",method = RequestMethod.POST) public String upload(@Reque ...
- JAVA不经过Catch(Exception e)直接到finally或者退出原因
今天遇到一个很奇葩的问题!在写Hadoop程序的时候!new一个对象!程序直接跑到finally代码块里面去了!Catch里面的Exception也没有执行. Configuration config ...
- SQL Server 本地时间和UTC时间的相互转换的代码
DECLARE @LocalDate DATETIME, @UTCDate DATETIME, @LocalDate2 DATETIME SET @LocalDate = GETDATE() SE ...
- linux ar 命令的使用说明那个和例子[转]
用途说明 创建静态库.a文件.用C/C++开发程序时经常用到,但我很少单独在命令行中使用ar命令,一般写在makefile中,有时也会在shell脚 本中用到.关于Linux下的库文件.静态库.动态库 ...
- HQL(Hibernate Query language)语言
现在有两张表:student(学生表),classroom(教室表). //对象 Student 对应 student 表中有四个字段,分别是:id,name,age,classroom; publi ...
- Android的AndroidManifest.xml文件的详解
一.关于AndroidManifest.xml AndroidManifest.xml 是每个android程序中必须的文件.它位于整个项目的根目录,描述了package中暴露的组件(activiti ...
- c#实现生产者消费者模式
; } Environment.ExitCode = result; } }}
- JS中的的Url传递中文参数乱码,如何获取Url中参数问题
一:Js的Url中传递中文参数乱码问题,重点:encodeURI编码,decodeURI解码: 1.传参页面Javascript代码:<script type=”text/javascript” ...