#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX 100000
struct Trie
{
int num;
Trie* next[10];
}a[MAX];
Trie root;
int location,num;
void initial()
{
root.num= -1;
memset( root.next, 0, sizeof(root.next) );
location= 0, num= 0;
}
void insert( char* s )
{
Trie* r= &root;
while( *s )
{
int t= *s- '0';
if( r->next[t]== NULL )
{
r->next[t]= &a[location];
a[location].num= -1;
memset( a[location].next, 0, sizeof(a[location].next) );
location++;
}
r= r->next[t];
s++;
}
if( r->num== -1 ) r->num= num++;
}
bool find( char* s )
{
Trie* r= &root;
while( *s )
{
int t= *s- '0';
if( r->next[t]== NULL ) return false;
r= r->next[t];
s++;
}
for( int i= 0; i< 10; ++i )
if( r->next[i] ) return true;
return false;
}
int n;
char str[10010][11];
int main()
{
int test;
scanf("%d",&test);
while( test-- )
{
scanf("%d",&n);
initial();
for( int i= 0; i< n; ++i )
{
scanf("%s", str[i] );
insert( str[i] );
}
bool ok= true;
for( int i= 0; i< n; ++i )
if( find( str[i] ) )
{
ok= false;
break;
}
if( ok ) puts("YES");
else puts("NO");
}
return 0;
}
posted on 2008-11-25 11:54
Darren 阅读(329)
评论(0) 编辑 收藏 引用