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

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

 #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. tableView特色用法

    // //  ViewController.m //  UITableView // //  Created by yhj on 15/12/15. //  Copyright © 2015年 QQ: ...

  2. OD调试2---TraceMe

    OD调试2---TraceMe 拆解一个Windows程序要比拆解一个DOS程序容易得多,因为在Windows中,只要API函数被使用,想对寻找蛛丝马迹的人隐藏一些东西是比较困难的.因此分析一个程序, ...

  3. [转]mac下Python升级到指定的版本

    以2.7升级到3.3为例1.删除原版本a)删除系统库中的版本sudo rm -R /System/Library/Frameworks/Python.framework/Versions/2.7 b) ...

  4. 配置sphinx

    1.先安装sphinxclient    #cd /usr/local/src    #wget http://sphinxsearch.com/files/sphinx-0.9.9.tar.gz   ...

  5. 【转】iOS代码规范

    原文地址: http://www.cocoachina.com/ios/20150908/13335.html 简介: 本 文整理自Apple文档<Coding Guidelines for C ...

  6. Dropdownlist的onchange事件应用

    function selectDpList(dp) { var sIndex = dp.selectedIndex;//返回选中是第几项 0,1.... var sText = dp.options[ ...

  7. USB封包格式

    1.起始(SOP)封包 根集线器会在每1 ms时,送出SOF封包.这介于2个SOF封包之间的时间,即称为帧(frame).SOF封包虽是属于令牌封包的一种,但却具有独自的PID形态名称SOF.通常目标 ...

  8. setAdapter(adapter)空指针nullPointer 解决办法

    setAdapter(adapter)空指针nullPointer 解决办法 (2014-06-13 10:01:23) 转载▼ 标签: 旅游 分类: Android开发 如果setAdapter报空 ...

  9. html模块一些方法

    <pre name="code" class="python"> find_by_tag_name: @elements = $h->find ...

  10. 【转】在Eclipse中安装和使用TFS插件

    文章地址:http://www.cnblogs.com/judastree/archive/2012/09/05/2672640.html 问题: 在Eclipse中安装和使用TFS插件. 解决过程: ...