Find the Clones Trie Tree
Time Limit: 5000MS | Memory Limit: 65536K | |
Total Submissions: 8306 | Accepted: 3130 |
Description
Input
The input is terminated by a block with n = m = 0 .
Output
Sample Input
9 6
AAAAAA
ACACAC
GTTTTG
ACACAC
GTTTTG
ACACAC
ACACAC
TCCCCC
TCCCCC
0 0
Sample Output
1
2
0
1
0
0
0
0
0
Hint
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<queue>
#include<deque>
#include<vector>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<fstream>
#include<memory>
#include<list>
#include<string>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MAXN 20003
#define L 20
#define INF 1000000009
#define eps 0.00000001
/*
给出多个DNA序列 要求有i份copy的DNA序列数
先插入结点 计算个数
最后搜一下
*/
int n, m;
int cnt[MAXN];
char s[L];
typedef struct Treenode
{
int cnt;
struct Treenode* Next[];
}*Tree;
Tree Newnode()
{
Tree T = (Tree)malloc(sizeof(Treenode));
memset(T->Next, NULL, sizeof(T->Next));
T->cnt = -;
return T;
}
void Insert(char s[], Tree T)
{
if (!T)
T = Newnode();
int p = ,k;
while (s[p])
{
if (s[p] == 'A') k = ;
else if (s[p] == 'C') k = ;
else if (s[p] == 'G') k = ;
else k = ;
if (!T->Next[k])
{
T->Next[k] = Newnode();
}
T = T->Next[k];
p++;
}
if (T->cnt == -)
T->cnt = ;
else
T->cnt++;
}
void dfs(Tree T)
{
if (!T) return;
if (T->cnt != -)
{
cnt[T->cnt]++;
return;
}
for (int i = ; i < ; i++)
dfs(T->Next[i]);
}
int main()
{
while (scanf("%d%d", &n, &m), n + m)
{
Tree T = Newnode();
memset(cnt, , sizeof(cnt));
for (int i = ; i < n; i++)
{
scanf("%s", s);
Insert(s, T);
}
dfs(T);
for (int i = ; i < n; i++)
{
printf("%d\n", cnt[i + ]);
}
}
return ;
}
Find the Clones Trie Tree的更多相关文章
- 关于Trie Tree简单实现
最近突然有兴致hiho一下了,实现了下trie tree,感觉而言,还是挺有意思的,个人觉得这货不光可以用来查单词吧,其实也可以用来替代Hash,反正查找,插入复杂度都挺低的,哈哈,啥都不懂,瞎扯.. ...
- 字典树(Trie Tree)
终于要开始更新我的ACM学习之路了,不过没想到却是因为一次Java大作业,有趣,%yuan老师. 字典树是一种很简单的树形结构,主要用来进行词频统计,在算法竞赛中有时也会碰到. 字典树的基本思路是,通 ...
- 笔试算法题(39):Trie树(Trie Tree or Prefix Tree)
议题:TRIE树 (Trie Tree or Prefix Tree): 分析: 又称字典树或者前缀树,一种用于快速检索的多叉树结构:英文字母的Trie树为26叉树,数字的Trie树为10叉树:All ...
- Phone List POJ 3630 Trie Tree 字典树
Phone List Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 29416 Accepted: 8774 Descr ...
- Trie tree实践
1.Trie树 Trie树即字典树或前缀树, 2.实践 代码实践如下: package cn.edu.buaa.trie; import java.util.HashSet; /** * @autho ...
- 字典树(Trie Tree)
在图示中,键标注在节点中,值标注在节点之下.每一个完整的英文单词对应一个特定的整数.Trie 可以看作是一个确定有限状态自动机,尽管边上的符号一般是隐含在分支的顺序中的.键不需要被显式地保存在节点中. ...
- hdu3724Encoded Barcodes(Trie tree)
题目请戳这里 题目大意:给n个字符串,给m个询问,每个询问给k个条形码.每个条形码由8个小码组成,每个小码有相应的宽度,已知一个条形码的宽度只有2种,宽的表示1,窄的表示0.并且宽的宽度是窄的宽度的2 ...
- trie tree(字典树)
hihocoder题目(http://hihocoder.com/problemset):#1014 trie树 #include <iostream> using namespace s ...
- POJ2945 Find the Clones trie树
建一颗$trie$树(当然你哈希也资瓷),边插边更新,看看搜到最底时有多少个字符串,然后更新. #include<cstdio> #include<iostream> #inc ...
随机推荐
- C# winform listBox中的项上下移动(转)
C# winform listBox中的项上下移动 分类: C# winform2009-06-24 12:37 876人阅读 评论(0) 收藏 举报 winformc#object //上移节点 ...
- LuoguP4365 [九省联考2018]秘密袭击
https://zybuluo.com/ysner/note/1141136 题面 求一颗大小为\(n\)的树取联通块的所有方案中,第\(k\)个数之和. \(n\leq1,667,k\leq n\) ...
- Java中继承,类的高级概念的知识点
1. 继承含义 在面向对象编程中,可以通过扩展一个已有的类,并继承该类的属性和行为,来创建一个新的类,这种方式称为继承(inheritance). 2. 继承的优点 A.代码的可重用性 B.子类可以扩 ...
- acc文件的运行
1.method 1: use "acc" >acc hello.acc world.mc <--- compilation will generate the hel ...
- 用JS将指定时间转化成用户当地时区的时间
公司的项目是面向海外用户的,但是最初的设计没考虑到时差问题,存入数据库的时间都是东八区的时间,导致现在补救有点坑爹...... 有一个需求是,产品详细页需要注明此款产品的开售时间,当海外的用户来访问这 ...
- 前端常见面试题总结part2
今天总结了几道,感觉非常有意思的题,有感兴趣的可以看下,有疑问请留言~ (答案在最后) 考察自执行函数的this指向 审题要细心 var n = 2, obj = { n:2, fn:(functio ...
- ACM_名字的价值
名字的价值 Time Limit: 2000/1000ms (Java/Others) Problem Description: 集训终于开始了,参加集训的人很多,也就有很多名字,集训组织者发现了一件 ...
- A - Team
Problem description One day three best friends Petya, Vasya and Tonya decided to form a team and tak ...
- Python启动浏览器Firefox\Chrome\IE
# -*- coding:utf-8 -*- import os import selenium from selenium import webdriver from selenium.webdri ...
- [转]ORACLE EXECUTE IMMEDIATE 小结
转自:http://www.cnblogs.com/huanghai223/archive/2011/06/29/2093660.html EXECUTE IMMEDIATE 代替了以前Oracl ...