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. Python 1 的数据类型

    Python3 中有六个标准的数据类型: Number(数字)String(字符串)List(列表)Tuple(元组)Sets(集合)Dictionary(字典) 1.Number(数字) pytho ...

  2. 我的npm笔记

    本文记录一些npm的使用技巧,主要包括自己常用的命令,做个备忘. NPM 是什么? NPM是NodeJS的包管理工具,现在已经进一步发展,致力于为很多其他平台提供包管理工具,其核心思想就是让包的安装更 ...

  3. yii2判断数据库字段is null

    $query = new Query; $query->select('ID, City,State,StudentName') ->from('student') ->]) -&g ...

  4. Java中finalize()用法

    Java中finalize()   垃圾回收器要回收对象的时候,首先要调用这个类的finalize方法(你可以 写程序验证这个结论),一般的纯Java编写的Class不需要重新覆盖这个方法,因为Obj ...

  5. 安装MySQL的详细步骤

    安装步骤如下: 1.打开网址:http://www.mysql.com/ ↓ 2.选择“Download”->“Windows”(此安装步骤只是在Window10 中进行,如有需要,其他系统可参 ...

  6. OpenGL学习进程(5)第三课:视口与裁剪区域

    本节是OpenGL学习的第三个课时,下面介绍如何运用显示窗体的视口和裁剪区域:     (1)知识点引入:     1)问题现象: 当在窗体中绘制图形后,拉伸窗体图形形状会发生变化: #include ...

  7. 【Head First Servlets and JSP】笔记15:建立一个JSP页面来显示被访问了多少次

    1.这是一个非常简单的程序,它看起来是这个样子的: 实际功能就是,每访问该页面一次count数加1,在服务器重启前(JVM重启前),这个次数将持续累加. 2.因为这个程序过于简单,所以我希望可以通过H ...

  8. Unity Json 之三

    今天在网上看到一个simplejson,直接调用这两个API就可以了,简单易用 string jsonstr = SimpleJson.SimpleJson.SerializeObject(json) ...

  9. 微服务(MicroServices)

    微服务Architecture(MicroServices) 微服务架构简单的定义 采用一组Service的方式来构建一个应用,服务独立部署在不同的进程(Container)中,不同Service通过 ...

  10. 语义web相关概念

    前言:最近做的项目是自然语言处理相关的,看了一本书<语义web技术基础>,总的来看,接触自然语言处理,语义理解也有差不多一年的时间了.这两天想了一想,自己究竟学到了什么,掌握了哪些新的知识 ...