#include<cstdio>
#include<iostream>
#include<string>
#include<cstdlib>
#define maxn 10
using namespace std;
struct
Tri
{

Tri*next[maxn];
int
num;
};

Tri *root;
void
buildTri(string ss)//建树的过程是一个动态的过程 动插的过程
{
Tri *p=root,*q;
for
(int i=;i<ss.size();i++)
{

int
id=ss[i]-'0';
if
(p->next[id]==NULL)
{

q=(Tri*)malloc(sizeof(Tri));
q->num=;
for
(int j=;j<maxn;j++) q->next[j]=NULL;
p->next[id]=q;
p=p->next[id];
}

else
p=p->next[id],p->num++;
}

p->num=-;// 作为结束的标志
}
int
findTri(string ss)
{

Tri *p=root,*q;
for
(int i=;i<ss.size();i++)
{

int
id=ss[i]-'0';
p=p->next[id];
if
(p==NULL) return;
if
(p->num==-) return -;
}

return
-;
}

void
del(Tri *root)
{

Tri *zz=root;
if
(zz==NULL) return;
for
(int i=;i<maxn;i++)
{

if
(zz->next[i]!=NULL) del(zz->next[i]);
}

free(zz);
}

int
main()
{

int
t;
cin>>t;
while
(t--)
{

root=(Tri*)malloc(sizeof(Tri));
for
(int i=;i<maxn;i++) root->next[i]=NULL;
root->num=;
int
ret;
cin>>ret;
string ss;
int
flag=;
while
(ret--)
{

cin>>ss;
if
(findTri(ss)==-) flag=;
// cout<<flag<<endl;
buildTri(ss);
}

del(root);
if
(flag) cout<<"YES"<<endl;
else
cout<<"NO"<<endl; }
return
;
}

hdu 1671 复习字典树的更多相关文章

  1. HDU 1671 (字典树统计是否有前缀)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1671 Problem Description Given a list of phone number ...

  2. hdu杭电1671 / poj3630 字典树

    传送门 题意:输入n串数字 找出是否有存在串的前缀与另一个串相同 如果存在 输出NO否则输出YES 思路:用字典树解决 标记字典树总串的结尾 查找出一个串内部是否有被标记的节点 如果有那么说明存在前缀 ...

  3. hdu 1979 DFS + 字典树剪枝

    http://acm.hdu.edu.cn/showproblem.php?pid=1979 Fill the blanks Time Limit: 3000/1000 MS (Java/Others ...

  4. hdu 2846(字典树)

    Repository Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  5. HDU 2846 Repository (字典树 后缀建树)

    Repository Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total ...

  6. HDU 2846 Repository(字典树,标记)

    题目 字典树,注意初始化的位置~!!位置放错,永远也到不了终点了org.... 我是用数组模拟的字典树,这就要注意内存开多少了,,要开的不大不小刚刚好真的不容易啊.... 我用了val来标记是否是同一 ...

  7. *hdu 5536(字典树的运用)

    Input The first line of input contains an integer T indicating the total number of test cases. The f ...

  8. three arrays HDU - 6625 (字典树)

    three arrays \[ Time Limit: 2500 ms \quad Memory Limit: 262144 kB \] 题意 给出 \(a\),\(b\) 数组,定义数组 \(c[i ...

  9. HDU 6625 (01字典树)

    题意:给定两个长为n的数组a和b:重新排列a和b,生成数组c,c[i]=a[i] xor b[i]:输出字典序最小的c数组. 分析:将a中的数插入一颗01字典树a中:将b中的数插入一颗01字典树b中: ...

随机推荐

  1. Leetcode题目300.最长上升子序列(动态规划-中等)

    题目描述: 给定一个无序的整数数组,找到其中最长上升子序列的长度. 示例: 输入: [10,9,2,5,3,7,101,18] 输出: 4 解释: 最长的上升子序列是 [2,3,7,101],它的长度 ...

  2. C++ STL copy copy_backward

    #include <iostream>#include <algorithm>#include <vector>#include <functional> ...

  3. HDFS的NameNode与SecondaryNameNode的工作原理

    原文:https://blog.51cto.com/xpleaf/2147375 看完之后确实对nameNode的工作更加清晰一些 在Hadoop中,有一些命名不好的模块,Secondary Name ...

  4. http://www.cda.cn/view/25735.html

    通过实例浅析Python对比C语言的编程思想差异 我一直使用 Python,用它处理各种数据科学项目. Python 以易用闻名.有编码经验者学习数天就能上手(或有效使用它). 听起来很不错,不过,如 ...

  5. Spring Boot设置定时任务

    在 http://start.spring.io/ 中新建一个Group为com.zifeiy,Artifact为task的工程. 然后在TaskApplication中添加注释:@EnableSch ...

  6. Go单引号和双引号区别

    首先做个测试,看下面那个选项是正确的: A. str:='abc'+'123'B. str:="abc"+"123"C. str:='123'+"ab ...

  7. 【OpenCV开发】使用OpenCV的OpenCL(ocl)模块

    参加OpenCV的OpenCL模块(以下称OCL)移植工作已经有2个月了.这里我说移植而不是开发,是因为大部分OCL模块的函数都是从已经很成熟的GPU模块移植过来的.于是目前阶段OCL模块所支持的函数 ...

  8. 【ARM-Linux开发】wayland和weston的介绍

    简单地说,Wayland是一套display server(Wayland compositor)与client间的通信协议,而Weston是Wayland compositor的参考实现.其官网为h ...

  9. 【DSP开发】CCS数据格式 load

    CCS支持的.dat文件详解(转载于hellodsp) CCS支持的.dat文件的格式为: 定数 数据格式 起始地址 页类型 数据块大小 1651 其后是文件内容,每行表示一个数据. 定数固定为&qu ...

  10. Spirng 分层,增加数据访问对象层

    到层关键注释 @Repository 对应的包 import org.springframework.stereotype.Repository;