Ancient Printer (Tire tree)

Source: Internet
Author: User

Ancient Printer

Time limit:2000/1000 MS (java/others) Memory limit:131072/65536 K (java/others)
Total submission (s): 1511 Accepted Submission (s): 748


Problem DescriptionThe Contest is beginning! While preparing the contest, ISea wanted to print the teams ' names separately in a single paper.
Unfortunately, what ISea could find is only a ancient printer:so ancient that can ' t believe it, it's only had three K Inds of operations:

' A '-' Z ': twenty-six letters you can type
' Del ': delete the last letter if it exists
' Print ': Print the word you had typed in the printer

The printer is empty in the beginning, ISea must with the three operations to print all the teams ' name, not necessarily I n the order in the input. Each time, he can type letters at the end of printer, or delete the last letter, or print the current word. After printing, the letters is stilling in the printer and you could delete some letters to print the next one, but you needn ' T delete the last word ' s letters.
ISea wanted to minimize the total number of operations, help him, please.

Inputthere is several test cases in the input.

Each test case is begin with one integer N (1≤n≤10000), indicating the number of team names.
Then N strings follow, each string only contains lowercases, not empty, and its length is no more than 50.

The input terminates by end of file marker.

Outputfor each test case, output one integer, indicating minimum number of operations.

Sample Input2freeradiantfreeopen Sample Output21 HintThe sample's Operation Is:f-r-e-e-o-p-e-n-print-del-del-del-del-r-a-d-i-a-n-t-print topic: similar to putting these words on the computer all over again, After entering a word need to delete, the last one does not need to delete, ask need to knock at least how many keys to think of tire tree is good to write. Using the tire tree to construct all the words, the construction of how many node memory to output the number of letters, because also to delete, so need to multiply 2, but we will put the longest word in the last input, and then eliminate the deletion, so need to add his strlen (), and then add the number of words =num_ Print;
1 /*******************************2 3 date:2015-12-09 22:15:294 AUTHOR:WQJ ([email protected])5 Link:http://www.cnblogs.com/a1225234/6 Name:7 8 ********************************/9#include <iostream>Ten#include <cstdio> One#include <algorithm> A#include <cmath> -#include <cstring> -#include <string> the#include <Set> -#include <vector> -#include <queue> -#include <stack> + #defineLL Long Long - using namespacestd; + structnode A { atnode* next[ -]; - node () -     { -          for(intI=0;i< -; i++) -next[i]=NULL; -     } in }; - intN; to Chara[ the]; + intans; -node*Root; the voidInsertChar* S,intlen) * { $     inti,j;Panax Notoginsengnode* p=Root; -      for(i=0; i<len;i++) the     { +         intpos=s[i]-'a'; A         if(p->next[pos]==NULL) the         { +ans++; -p->next[pos]=Newnode; $P=p->Next[pos]; $         } -         Else -P=p->Next[pos]; the     } -     return;Wuyi } the intMain () - {     WuFreopen ("In.txt","R", stdin); -      while(SCANF ("%d", &n)! =EOF) About     { $         inti,j; -         intmax=0; -ans=0; -root=Newnode; A          for(i=0; i<n;i++) +         { thescanf"%s", a); -             intlen=strlen (a); $max=Max (Max,len); the Insert (A,len); the         } theprintf"%d\n", ans*2+n-Max); the     } -     return 0; in}

Ancient Printer (Tire tree)

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.