#include <cstdio>
#include <iostream>
using namespace std;
const int maxn=10;
bool ok;
typedef struct note
{
bool isphone;
struct note *next[maxn];
}trie;
void insert(trie *root,const char *ch)
{
trie *p=root;
while(*ch!='\0')
{
if(p->next[*ch-48]==NULL)
{
trie *temp=(trie *)malloc(sizeof(trie));
temp->isphone=false;
for(int i=0;i<maxn;i++)
temp->next[i]=NULL;
p->next[*ch-48]=temp;
}
if(p->isphone==true)
ok=1;
p=p->next[*ch-48];
ch++;
}
for(int i=0;i<maxn;i++)
if(p->next[i]!=NULL)
ok=1;
p->isphone=true;
}
void del(trie *root)
{
for(int i=0;i<maxn;i++)
{
if(root->next[i]!=NULL)
{
del(root->next[i]);
}
}
free(root);
}
int main()
{
int cas;
scanf("%d",&cas);
while(cas--)
{
trie *root=(trie *)malloc(sizeof(trie));
root->isphone=false;
for(int i=0;i<maxn;i++)
root->next[i]=NULL;
int n;
char ch[maxn+2];
scanf("%d",&n);
ok=0;
while(n--)
{
scanf("%s",ch);
if(!ok)
insert(root,ch);
}
if(ok)
printf("NO\n");
else
printf("YES\n");
del(root);
}
return 0;
}
hdu 1671 字典树
最新推荐文章于 2019-12-18 20:08:00 发布