Phone List (HDOJ-1671) (Tire tree)

Source: Internet
Author: User
Tags bool include return

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 
        
       
      
     
    
  
 


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.