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 ...
随机推荐
- HDU-简单计算器-1237
这道题我做了一天,把中缀表达式转化为后缀表达式,但遇到了储存的问题,考虑了好久,写出后又调试,弄了一天,下面说一下中缀表达式转换后缀表达式: 算法: 中缀表达式转后缀表达式的方法: 1.遇到操作数:直 ...
- php对数组中指定键值排序
function array_sort($arr,$keys,$type='asc'){ $keysvalue = $new_array = array(); foreach ($arr as $k= ...
- 高手总结的CSS执行顺序及其优先权问题汇总
今天在看一本书时又看到了”CSS优 先权“这个问题,感觉这个问题还是比较重要的,也算是样式的特异性吧,尤其是在面对较多.较深层.较复杂的样式属性时,理解CSS的加权计算方法对于重写 样式属性之类的问题 ...
- setInterval()-----------js 函数总结
setInterval() 方法可按照指定的周期(以毫秒计)来调用函数或计算表达式. setInterval() 方法会不停地调用函数,直到 clearInterval() 被调用或窗口被关闭.由 s ...
- uWSGI
参考:http://perlmaven.com/deploying-pyton-with-uwsgi-on-ubuntu-13-10
- 3D Touch:静态快速启动方式
原文传送门:Add iOS 9’s Quick Actions shortcut support in 15 minutes right now ! 苹果在iOS9 上引入3D触控(压力触控)功能 ...
- JavaScript事件处理
客户端javascript程序采用了异步事件驱动程序,在这种程序设计风格下,当文档,浏览器,元素,或与之相关的对象发生某些有趣的事件时,web浏览器就会产生事件.事件本身不是javascript对象. ...
- Lars Knoll 宣布了Qt 5有四大目标
作者:廖梓跃链接:http://www.zhihu.com/question/19636309/answer/13097572来源:知乎著作权归作者所有,转载请联系作者获得授权. 自诺基亚宣布转向Wi ...
- Qt中一些常用的格式转换
转自:http://blog.csdn.NET/yh_1988/article/details/7190356 用Qt经常头痛于一些格式不能通用的问题 在此记录备用 1 (20120112)QStri ...
- UESTC_Little Deer and Blue Cat CDOJ 1025
In DOTA, there are two Intellegence heroes. One is Enchantress, who is usually called Little Deer by ...