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 ...
随机推荐
- bnuoj 1057 函数(模拟)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=1057 [题意]:给定x的值,带入f(x)求函数值 [题解]:注意第一个数的符号可能是'+',这里把我 ...
- CentOS安装crontab及使用方法
crontab命令常见于Unix和类Unix的操作系统之中,用于设置周期性被执行的指令.该命令从标准输入设备读取指令,并将其存放于 “crontab”文件中,以供之后读取和执行.通常,crontab储 ...
- Mybatis 示例之 SelectKey(转)
参考:http://blog.csdn.net/isea533/article/details/21153791 SelectKey在Mybatis中是为了解决Insert数据时不支持主键自动生成的问 ...
- CrackMe_001
本系列文章的目的是从一个没有任何经验的新手的角度(其实就是我自己),一步步尝试将160个CrackMe全部破解,如果可以,通过任何方式写出一个类似于注册机的东西. 其中,文章中按照如下逻辑编排(解决如 ...
- nginx上用fastcgi配置python环境
费了2天的功夫,翻阅了无数的中文.英文资料,终于搞定.写下此文留待以后翻阅用 本文环境,centOS 5.4 ,Nignx-0.8.49, Python 2.6.5 ========== ...
- nginx几个知识点汇总
WHY? 为什么用Nginx而不用LVS? 7点理由足以说明一切:1 .高并发连接: 官方测试能够支撑 5 万并发连接,在实际生产环境中跑到 2 - 3 万并发连接数.?2 .内存消耗少: 在 3 万 ...
- Hibernate逍遥游记-第2章-使用hibernate.properties
1. package mypack; import org.hibernate.*; import org.hibernate.cfg.Configuration; import java.util. ...
- SQL 2008 R2 启动失败 提示 请求失败或服务未及时响应
为什么启动sql server 配置管理器出现请求失败或服务未及时响应_百度知道 http://zhidao.baidu.com/link?url=ElemzIan6I2CqJsd7-7uk5TV25 ...
- 102. Binary Tree Level Order Traversal
题目: Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to ri ...
- SGU 101 修改
感谢这里. test4确实是个不连通的case,奇怪的是我用check函数跟if (check() == false)来判断这个case,当不连通时就死循环,得到的结果是不一样的,前者得到WA,后者得 ...