Trie树模板题
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int ans;
char str[205];
struct Trie
{
int index;
Trie *next[10];
Trie()
{
index=0;
memset(next,0,sizeof(next));
}
};
void Insert(Trie *tr,char *s,int len)
{
tr->index++;
ans=max(ans,tr->index*len);
if(*s!='\0')
{
if(tr->next[*s-'0']==0)
tr->next[*s-'0']=new Trie;
Insert(tr->next[*s-'0'],s+1,len+1);
}
}
int main()
{
int T,n,i,j,k;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
Trie *root=new Trie;
ans=0;
while(n--)
{
scanf("%s",str);
Insert(root,str,0);
}
printf("%d\n",ans);
}
return 0;
}