Time Limit: 5000MS   Memory Limit: 65536K
Total Submissions: 8306   Accepted: 3130

Description

Doubleville, a small town in Texas, was attacked by the aliens. They have abducted some of the residents and taken them to the a spaceship orbiting around earth. After some (quite unpleasant) human experiments, the aliens cloned the victims, and released multiple copies of them back in Doubleville. So now it might happen that there are 6 identical person named Hugh F. Bumblebee: the original person and its 5 copies. The Federal Bureau of Unauthorized Cloning (FBUC) charged you with the task of determining how many copies were made from each person. To help you in your task, FBUC have collected a DNA sample from each person. All copies of the same person have the same DNA sequence, and different people have different sequences (we know that there are no identical twins in the town, this is not an issue).

Input

The input contains several blocks of test cases. Each case begins with a line containing two integers: the number 1 ≤ n ≤ 20000 people, and the length 1 ≤ m ≤ 20 of the DNA sequences. The next n lines contain the DNA sequences: each line contains a sequence of m characters, where each character is either `A', `C', `G' or `T'.

The input is terminated by a block with n = m = 0 .

Output

For each test case, you have to output n lines, each line containing a single integer. The first line contains the number of different people that were not copied. The second line contains the number of people that were copied only once (i.e., there are two identical copies for each such person.) The third line contains the number of people that are present in three identical copies, and so on: the i -th line contains the number of persons that are present in i identical copies. For example, if there are 11 samples, one of them is from John Smith, and all the others are from copies of Joe Foobar, then you have to print `1' in the first andthe tenth lines, and `0' in all the other lines.

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

Huge input file, 'scanf' recommended to avoid TLE. 
#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的更多相关文章

  1. 关于Trie Tree简单实现

    最近突然有兴致hiho一下了,实现了下trie tree,感觉而言,还是挺有意思的,个人觉得这货不光可以用来查单词吧,其实也可以用来替代Hash,反正查找,插入复杂度都挺低的,哈哈,啥都不懂,瞎扯.. ...

  2. 字典树(Trie Tree)

    终于要开始更新我的ACM学习之路了,不过没想到却是因为一次Java大作业,有趣,%yuan老师. 字典树是一种很简单的树形结构,主要用来进行词频统计,在算法竞赛中有时也会碰到. 字典树的基本思路是,通 ...

  3. 笔试算法题(39):Trie树(Trie Tree or Prefix Tree)

    议题:TRIE树 (Trie Tree or Prefix Tree): 分析: 又称字典树或者前缀树,一种用于快速检索的多叉树结构:英文字母的Trie树为26叉树,数字的Trie树为10叉树:All ...

  4. Phone List POJ 3630 Trie Tree 字典树

    Phone List Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 29416   Accepted: 8774 Descr ...

  5. Trie tree实践

    1.Trie树 Trie树即字典树或前缀树, 2.实践 代码实践如下: package cn.edu.buaa.trie; import java.util.HashSet; /** * @autho ...

  6. 字典树(Trie Tree)

    在图示中,键标注在节点中,值标注在节点之下.每一个完整的英文单词对应一个特定的整数.Trie 可以看作是一个确定有限状态自动机,尽管边上的符号一般是隐含在分支的顺序中的.键不需要被显式地保存在节点中. ...

  7. hdu3724Encoded Barcodes(Trie tree)

    题目请戳这里 题目大意:给n个字符串,给m个询问,每个询问给k个条形码.每个条形码由8个小码组成,每个小码有相应的宽度,已知一个条形码的宽度只有2种,宽的表示1,窄的表示0.并且宽的宽度是窄的宽度的2 ...

  8. trie tree(字典树)

    hihocoder题目(http://hihocoder.com/problemset):#1014 trie树 #include <iostream> using namespace s ...

  9. POJ2945 Find the Clones trie树

    建一颗$trie$树(当然你哈希也资瓷),边插边更新,看看搜到最底时有多少个字符串,然后更新. #include<cstdio> #include<iostream> #inc ...

随机推荐

  1. svn for vs

    现在官方下载需要注册一堆的东西,为方便群众使用在这里提供一个新版的下载. http://files.cnblogs.com/wfcfan/AnkhSvn-2.5.12266.rar

  2. LuoguP3621 [APIO2007]风铃

    https://zybuluo.com/ysner/note/1140124 题面 题面复杂,戳我 解析 看着这道题... 似乎与[HNOI/AHOI2018]道路有不可言妙的相似之处. (题面吓人, ...

  3. Java 发送短信

    这是一个调用sms接口发短信的程序,支持同时发送的短信量并不是很大,只作为学习使用(当然如果你想内部使用也行) 源码:package com; import org.apache.commons.ht ...

  4. PCB LDI文件 自动化输出(改造)实现思路

    由于工厂采用Liunxs系统输出LDI文件,由于我们数据库是用的Windows Server,编程语言是.net 无法与Liunxs系统进行有效对接, 所以造成才会造成LDI 资料输效率极低,人员工作 ...

  5. E20170830-mk

    translation  n. 翻译; 译本; 转化; 转变; calculate  vt. 计算; 估计; 打算,计划; 旨在; erase  vt. 抹去; 清除; 擦掉;

  6. 7.Flask-上传文件和访问上传的文件

     1.1.上传文件和访问上传的文件 upload_file_demo.py from flask import Flask,request,render_template import os from ...

  7. ROS-URDF-活动关节

    前言:介绍活动关节,并使机器人活动起来. 参考自:http://wiki.ros.org/urdf/Tutorials/Building%20a%20Movable%20Robot%20Model%2 ...

  8. [Luogu 1850] noip16 换教室

    [Luogu 1850] noip16 换教室 好久没有更博客了,先唠嗑一会,花了两天的空闲时间大致做完了昨年的noip真题 虽然在经过思考大部分题目都可出解(天天爱跑步除外),但是并不知道考试时候造 ...

  9. Visual Studio切换界面显示语言

    [工具]-[选项]-[环境]-[区域设置]-[语言]-[获取其他语言] 安装后重启即可.

  10. spring 九种设计模式

    spring中常用的设计模式达到九种,我们举例说明: 第一种:简单工厂 又叫做静态工厂方法(StaticFactory Method)模式,但不属于23种GOF设计模式之一. 简单工厂模式的实质是由一 ...