lightoj 1224
很简单的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的更多相关文章
- LightOJ 1224 - DNA Prefix - [字典树上DFS]
题目链接:https://cn.vjudge.net/problem/LightOJ-1224 Given a set of $n$ DNA samples, where each sample is ...
- LightOJ 1224 DNA Prefix
Given a set of n DNA samples, where each sample is a string containing characters from {A, C, G, T}, ...
- 区间DP LightOJ 1422 Halloween Costumes
http://lightoj.com/volume_showproblem.php?problem=1422 做的第一道区间DP的题目,试水. 参考解题报告: http://www.cnblogs.c ...
- LightOj 1298 - One Theorem, One Year(DP + 欧拉)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1298 题意:给你两个数 n, p,表示一个数是由前 k 个素数组成的,共有 n 个素数 ...
- 1214 - Large Division -- LightOj(大数取余)
http://lightoj.com/volume_showproblem.php?problem=1214 这就是一道简单的大数取余. 还想还用到了同余定理: 所谓的同余,顾名思义,就是许多的数被一 ...
- LightOJ Beginners Problems 部分题解
相关代码请戳 https://coding.net/u/tiny656/p/LightOJ/git 1006 Hex-a-bonacci. 用数组模拟记录结果,注意取模 1008 Fibsieve's ...
- LightOJ 1341 唯一分解定理
Aladdin and the Flying Carpet Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%lld &a ...
- lightoj 1370 欧拉函数
A - Bi-shoe and Phi-shoe Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & % ...
- lightoj 1074 spfa判断负环
Extended Traffic Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Sub ...
随机推荐
- 【BZOJ 1054】 [HAOI2008]移动玩具
Description 在一个4*4的方框内摆放了若干个相同的玩具,某人想将这些玩具重新摆放成为他心中理想的状态,规定移动时只能将玩具向上下左右四个方向移动,并且移动的位置不能有玩具,请你用最少的移动 ...
- Mapped Statements collection does not contain value for ResearcherMapper.方法名
搞了半天, 原来是映射文件没加, 新手常遇到的问题. Mapped Statements collection does not contain value for后面是什么类什么方法之类的: 错误原 ...
- Dapper使用方法
这里记下Dapper容易忘的使用方法: 返回的数据可以有相同名称的列,会分配到不同的类上,默认使用Id这个列作为分割列 connection.Open(); //手动打开的话会保持长连接,否则每次查 ...
- Delphi XE5 android 蓝牙通讯传输
不多讲,直接上代码了. 代码来自网络 http://files.cnblogs.com/nywh2008/Bluetooth_LEDs_android.rar
- eclipse/MyEclipse 日期格式、注释日期格式、时区问题
eclipse/MyEclipse 日期格式.注释日期格式.时区问题 在eclipse/MyEclipse中,如果你的注释或是运行System.out.print(new java.util.Date ...
- office安装不了 “windows installer 服务不能更新一个或多个受保护的windows文件”
出现这种情况可能是系统中某些文件缺失了,一般发生于安装GHOST版或做过精简的系统 打开C:\WINDOWS\msagent 看看文件夹中内容是不是如下图所示: 再打开C:\Program Files ...
- [转载]Eziriz .NET Reactor 4.7.0.0 官方原版+破解补丁(强大的代码保护和软件防盗版工具)
Eziriz .NET Reactor 是一个强大的代码保护和软件防盗版工具,完全由.NET框架编写..NET Reactor支持NET平台的软件许可系统,并支持NET程序集所有语言.当.Net编译器 ...
- [BEC][hujiang] Lesson03 Unit1:Working life ---Grammar & Listening & Vocabulary
3 Working life p8 Grammar Gerund and infinitive(动名词和不定式) 一般而言: 1 动词后面接动名词还是不定式没有特定规则,主要取决于语言习 ...
- Python性能鸡汤
http://pythoner.org/wiki/257/ 毫无疑问:Python程序没有编译型语言高效快速. 甚至Python拥护者们会告诉你Python不适合这些领域. 然而,YouTube已用P ...
- C++转换unicode utf-8 gb2312编码
windows开发环境下用VC++6.0 对unicode .utf-8. gb2312 三种编码格式之间的转换方法: #include <iostream> #include <s ...