很简单的Trie树,记录每个前缀的次数,dfs一次Trie即可

#include<set>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<cmath>
#include<ctime>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<cstdlib>
#include<sstream>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long
#define INF 0x7fffffff
#define debug cout << "here" << endl
#define CLR(X, Y) memset(X, Y sizeof Y)
#define FOR(X, Y) for(int i = X;i < Y;i ++)
inline int myMin(int x, int y){return x < y ? x : y;}
inline int myMax(int x, int y){return x < y ? y : x;}
struct Node{
int cnt;
Node* child[4];
Node(){
cnt = 0;
for(int i = 0;i < 4;i ++) child[i] = NULL;
}
};
int ans;
Node *root;
int Hash(char c){
if(c == 'A') return 0;
if(c == 'G') return 1;
if(c == 'C') return 2;
if(c == 'T') return 3;
} void insert(char* str){
Node *tmp = root;
while(str[0]){
int idx = Hash(str[0]);
if(tmp->child[idx] == NULL) tmp->child[idx] = new Node();
tmp = tmp->child[idx];
tmp->cnt ++;
str++;
}
} void dfs(int dep, Node *tmp){
if(dep*tmp->cnt > ans) ans = dep*tmp->cnt;
for(int i = 0;i < 4;i ++){
if(tmp->child[i]) dfs(dep+1, tmp->child[i]);
}
} int main(int argc, char* argv[]){
char str[55];
int t, n, CASE(0);
// freopen("in.cpp", "r", stdin);
scanf("%d", &t);
while(t--){
root = new Node();
scanf("%d", &n);
for(int i = 0;i < n;i ++){
scanf("%s", str);
insert(str);
}
ans = 0;
dfs(0, root);
printf("Case %d: %d\n", ++CASE, ans);
}
return 0;
}

树即可,

lightoj 1224的更多相关文章

  1. LightOJ 1224 - DNA Prefix - [字典树上DFS]

    题目链接:https://cn.vjudge.net/problem/LightOJ-1224 Given a set of $n$ DNA samples, where each sample is ...

  2. LightOJ 1224 DNA Prefix

    Given a set of n DNA samples, where each sample is a string containing characters from {A, C, G, T}, ...

  3. 区间DP LightOJ 1422 Halloween Costumes

    http://lightoj.com/volume_showproblem.php?problem=1422 做的第一道区间DP的题目,试水. 参考解题报告: http://www.cnblogs.c ...

  4. LightOj 1298 - One Theorem, One Year(DP + 欧拉)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1298 题意:给你两个数 n, p,表示一个数是由前 k 个素数组成的,共有 n 个素数 ...

  5. 1214 - Large Division -- LightOj(大数取余)

    http://lightoj.com/volume_showproblem.php?problem=1214 这就是一道简单的大数取余. 还想还用到了同余定理: 所谓的同余,顾名思义,就是许多的数被一 ...

  6. LightOJ Beginners Problems 部分题解

    相关代码请戳 https://coding.net/u/tiny656/p/LightOJ/git 1006 Hex-a-bonacci. 用数组模拟记录结果,注意取模 1008 Fibsieve's ...

  7. LightOJ 1341 唯一分解定理

    Aladdin and the Flying Carpet Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%lld &a ...

  8. lightoj 1370 欧拉函数

    A - Bi-shoe and Phi-shoe Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & % ...

  9. lightoj 1074 spfa判断负环

     Extended Traffic Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Sub ...

随机推荐

  1. 【BZOJ 1911】 [Apio2010]特别行动队

    Description Input Output Sample Input 4 -1 10 -20 2 2 3 4 Sample Output 9 HINT   转移方程 f[i]=max(f[j]+ ...

  2. MyEclipse 8.5配置Tomcat7.0

    MyEclipse 8.5配置默认没有Tomcat7.0, 如果想使用怎么办.? window>>Preferences>>MyEclipse Enterprise Workb ...

  3. 请求管道与IHttpModule接口

    IHttpModule向实现类提供模块初始化和处置事件.  IHttpModule包含兩個方法: public void Init(HttpApplication context);public vo ...

  4. 明晰三种常见存储技术:DAS、SAN和NAS

    随着企业网络应用的时间和应用的数据量的加大,企业已经感觉到存储容量和性能落后与网络的应用发展需求,特别是流媒体企业,在这种应用条件下满足用户的存储需求的技术应用诞生,DAS.NAS和SAN三种存储技术 ...

  5. eclipse/MyEclipse 日期格式、注释日期格式、时区问题

    eclipse/MyEclipse 日期格式.注释日期格式.时区问题 在eclipse/MyEclipse中,如果你的注释或是运行System.out.print(new java.util.Date ...

  6. log4j示例

    示例代码:此示例从控制台输入日志,设置了输出等级. # # Log4J Settings for log4j 1.2.x (via jakarta-commons-logging) # # The f ...

  7. 10+ 最流行的 jQuery Tree 菜单插件

    jstree – jQuery Tree Plugin With HTML & JSON Data jstree is a lightweight and flexible jQuery pl ...

  8. P​H​P​ ​5​.​3​连​接​s​q​l​ ​s​e​r​v​e​r​ ​2​0​0​8​ ​R​2

    我的机器为: xp sp3 sql server 2008 developer apache 2.2.2 php 5.3  从5.3开始,php就不再提供mssql.dll了,所以要php连接sql  ...

  9. Redis hash数据类型操作

    Redis hash是一个string类型的field和value的映射表.一个key可对应多个field,一个field对应一个value.将一个对象存储 为hash类型,较于每个字段都存储成str ...

  10. 分布式设计与开发(三)------高一致性服务ZooKeeper

    分布式环境中大多数服务是允许部分失败,也允许数据不一致,但有些最基础的服务是需要高可靠性,高一致性的,这些服务是其他分布式服务运转的基础,比如naming service.分布式lock等,这些分布式 ...