Find prefix length * Maximum number of strings that match the prefix
By the way, I practiced the template of the dictionary tree.
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cstdlib>5 using namespacestd;6 structtrie{7Trie *next[2];8 intIndex//Quantity9 };TenInline trie*NewNode () One { ATrie *T; -T= (trie*)malloc(sizeof(Trie)); -memset (T,0,sizeof(trie));// !!!!! the returnT; - } - intT,n,ans; - Chars[205]; + voidInsert (Trie *s,Charx[]) - { + inti,k; ATrie *T; at for(i=0; x[i];i++) - { -k=x[i]-'0'; - if(S->next[k]) s=s->Next[k]; - Else{ -t=NewNode (); ins->next[k]=T; -s=T; to } +s->index++; - } the } * voidFind (Trie *s,intx) $ {Panax Notoginseng inti,k; - for(i=0;i<2; i++) the { + if(s->Next[i]) { AAns=max (ans,s->next[i]->index*x); theFind (s->next[i],x+1);//Look down + } - } $ } $ intMain () - { -scanf"%d",&t); the while(t--) - {Wuyiscanf"%d",&n); thetrie* root=NewNode (); - for(intI=1; i<=n;++i) Wu { -scanf"%s", s); About Insert (root,s); $ } -ans=0; -Find (Root,1); -printf"%d\n", ans); A } +}
UVa 11488-hyper Prefix Sets