#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, 
0sizeof(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, 
0sizeof(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
++;
    }
    
    
forint 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();
        
        
forint i= 0; i< n; ++i ) 
        {
            scanf(
"%s", str[i] );
            insert( str[i] );
        }
        
        
bool ok= true;
        
forint 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 阅读(323) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理