Given a set of n DNA samples, where each sample is a string containing characters from {A, C, G, T}, we are trying to find a subset of samples in the set, where the length of the longest common prefix multiplied by the number of samples in that subset is maximum.

To be specific, let the samples be:

ACGT

ACGTGCGT

ACCGTGC

ACGCCGT

If we take the subset {ACGT} then the result is 4 (4 * 1), if we take {ACGT, ACGTGCGT, ACGCCGT} then the result is 3 * 3 = 9 (since ACG is the common prefix), if we take {ACGT, ACGTGCGT, ACCGTGC, ACGCCGT} then the result is 2 * 4 = 8.

Now your task is to report the maximum result we can get from the samples.

Input

Input starts with an integer T (≤ 10), denoting the number of test cases.

Each case starts with a line containing an integer n (1 ≤ n ≤ 50000) denoting the number of DNA samples. Each of the next n lines contains a non empty string whose length is not greater than 50. And the strings contain characters from {A, C, G, T}.

Output

For each case, print the case number and the maximum result that can be obtained.

Sample Input

3

4

ACGT

ACGTGCGT

ACCGTGC

ACGCCGT

3

CGCGCGCGCGCGCCCCGCCCGCGC

CGCGCGCGCGCGCCCCGCCCGCAC

CGCGCGCGCGCGCCCCGCCCGCTC

2

CGCGCCGCGCGCGCGCGCGC

GGCGCCGCGCGCGCGCGCTC

Sample Output

Case 1: 9

Case 2: 66

Case 3: 20

Note

Dataset is huge. Use faster I/O methods.

字典树,保证空间充足否则re。

代码:

    #include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
using namespace std;
int n,t,pos;
int trie[][];
int num[];
int ans;
int to[];
void Insert(char *s) {
int i = ,c = ;
while(s[i]) {
int d = to[s[i]];
if(!trie[c][d]) {
trie[c][d] = ++ pos;
}
c = trie[c][d];
ans = max(ans,++ num[c] * ++ i);
}
}
int main() {
to['A'] = ;
to['C'] = ;
to['G'] = ;
to['T'] = ;
scanf("%d",&t);
char s[];
for(int i = ;i <= t;i ++) {
scanf("%d",&n);
pos = ;
memset(num,,sizeof(num));
memset(trie,,sizeof(trie));
ans = ;
for(int j = ;j < n;j ++) {
scanf("%s",s);
Insert(s);
}
printf("Case %d: %d\n",i,ans);
}
}

LightOJ 1224 DNA Prefix的更多相关文章

  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 DNA Prefix(字典树+dfs)

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=121897#problem/F F - DNA Prefix Time Limit:200 ...

  3. lightoj 1224

    很简单的Trie树,记录每个前缀的次数,dfs一次Trie即可 #include<set> #include<map> #include<list> #includ ...

  4. GenomicRangeQuery /codility/ preFix sums

    首先上题目: A DNA sequence can be represented as a string consisting of the letters A, C, G and T, which ...

  5. 【题解】【数组】【Prefix Sums】【Codility】Genomic Range Query

    A non-empty zero-indexed string S is given. String S consists of N characters from the set of upper- ...

  6. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) E. DNA Evolution 树状数组

    E. DNA Evolution 题目连接: http://codeforces.com/contest/828/problem/E Description Everyone knows that D ...

  7. prefix sums--codility

    lesson 5: prefix sums 1. PassingCars 2. CountDiv 3. GenomicRangeQuery 4. MinAvgTwoSlice lesson 5: pr ...

  8. Codeforces - 828E DNA Evolution —— 很多棵树状数组

    题目链接:http://codeforces.com/contest/828/problem/E E. DNA Evolution time limit per test 2 seconds memo ...

  9. hbase_异常_03_java.io.EOFException: Premature EOF: no length prefix available

    一.异常现象 更改了hadoop的配置文件:core-site.xml  和   mapred-site.xml  之后,重启hadoop 和 hbase 之后,发现hbase日志中抛出了如下异常: ...

随机推荐

  1. springboot-数据库

    Spring-data-jpa jpa定义了一系列持久化的标准,比如hibernate就实现了这一标准. Springboot 的jpa就是hibernate的整合. 在pom文件中增加配置: < ...

  2. HTTP学习笔记05-首部

    首部和方法配合工作共同决定了客户端和服务器能做些什么事情. 首部可以出现在请求和响应报文中,大致来分的话,可以分为那么5种: 通用首部: request和response报文都可以使用的首部. 比如 ...

  3. iOS上架被拒原因及解决办法

    简单的记录一下,近期APP上架所遇到的坑爹事儿吧!! 第一次提交: 第二天给了回复,内容如下: .Guideline - Performance - Software Requirements You ...

  4. Unity发布安卓后,安卓输入键盘字体白色

    项目里需要用到显示手机电池电量的,但是又不想写安卓,倒jar包,还要做配置,还要写IOS,好麻烦的说.一查,unity后期版本有这个API,索性就升级高版本的了.但是遇到个小问题,那就是安卓输入的时候 ...

  5. VMware Big Data Extensions 安装步骤

    文档地址:https://pubs.vmware.com/bde-2/index.jsp 第一步,部署BigDataExtensions OVF模板,并登陆Console修改默认密码 第二步,在 Se ...

  6. MVC6 (ASP.NET5) 自定义TagHelper

    1) 在 _ViewImports.cshtml 中引入TagHelper类所在的 Assembly . (注意不是namespace)  : @addTagHelper "*, WebAp ...

  7. [转载]spring security 的 logout 功能

    原文地址:security 的 logout 功能">spring security 的 logout 功能作者:sumnny 转载自:http://lengyun3566.iteye ...

  8. Spring Boot 注释

    1.@RestController@RestController ≍ @Controller + @ResponseBody在Controller文件 public class xxxx 前面加用于返 ...

  9. Oracle创建表空间和增加表空间

    1.创建表空间 create tablespace fgq datafile 'E:\app\Administrator\oradata\fms\fgq01.dbf' size 1000M autoe ...

  10. java中i=i++问题分析

    http://www.ticmy.com/?p=43 重点:局部变量表 和 操作数栈的执行过程. 使用javac编译后再使用javap -c Test反编译这个类查看它的字节码,如下(只摘取main方 ...