Phone List (HDOJ-1671) (tire tree)

Source: Internet
Author: User

Phone List (HDOJ-1671) (tire tree)

A positive solution is a dictionary tree that uses a linked list to construct a data structure similar to a binary tree in zishu. Because the memory for this question is relatively tight, you need to solve the memory problem. However, if you release the memory recursively, the efficiency will be low. The solution is to open a memory pool (array ), each time the subscript is updated, it can be reused.

 

#include
 
  #include
  
   #include
   
    #includeusing 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
     
      

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.