The positive solution is the dictionary tree, uses the link list realization one kind of data structure, constructs the way and Purple book's two fork tree almost. Because the memory of this problem is relatively tight, you need to solve the memory problem, but if the recursive release of memory will lead to inefficient, the solution is to open a memory pool (array), each update subscript can be reused.
#include
#include
#include
#include
using namespace std; int t,n,k; struct pa{char s[15]; int Len; }; BOOL CMP (PA A,pa b) {return a.len>b.len;} struct trie{trie *next[15]; Trie *root; Trie all_trie[1000000]; BOOL Built (char *s,int len) {bool ok = true; Trie *p = root, *q; for (int i=0;i
next[id]==null) {OK = False ; Q = &all_trie[k++]; for (int j=0;j<10;j++) q->next[j] = NULL; P->next[id] = q; p = p->next[id]; } else {p = p->next[id];}} return OK; int main () {scanf ("%d", &t); while (t--) {scanf ("%d", &n); Pa s[10005]; k = 0; bool ok = true; root = &all_trie [k++]; for (int i=0;i<10;i++) root->next[i] = NULL; for (int i=0;i