Algorithm title: Hdu 3460 Ancient Printer

Source: Internet
Author: User
Tags time limit

Link:

http://acm.hdu.edu.cn/showproblem.php?pid=3460

Topic:

Ancient Printer

Time limit:2000/1000 MS (java/others) Memory limit:131072/65536 K (java/others)

Total submission (s): 955 accepted submission (s): 441

Problem Description

The contest is beginning! While preparing the contest, ISea wanted to print the teams ' names ' in a single separately.

Unfortunately, what ISea could find is only a ancient printer:so the ancient it you can ' t believe it, it 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 have 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 in the end of printer, or deletes the last letter, or print the current word. After printing, the letters are stilling at the printer, you could delete some letters to print the next one and but you Needn ' T deletes the last word ' s letters.

ISea wanted to minimize the total number of operations, help him, please.

Input

There are several test cases in the input.

Each test case is begin with one integer N (1≤n≤10000) and indicating the number of team names.

Then N strings Follow, each string of only contains lowercases, not empty, and its length are no more than 50.

The input terminates by end of file marker.

Output

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

Sample Input

2 Freeradiant Freeopen

Sample Output

21st

Hint

The 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

Analysis and Summary:

This problem is last night before bedtime 1 hours to do, first look feel very water, direct traverse, according to the path taken to count, back to count (if all finished printing, then back to the count no longer).

The sample had to come out happy to submit, the result WA was a mess. After changing a few places or WA, and then went to bed first.

The next day to wake up to think of this problem, found that the count is not possible. Because such a child traversal, the last word traversal must be the largest dictionary, but the dictionary order is not necessarily the shortest, should choose the longest word in the last print, this way to save the shortest step.

Therefore, the direct traversal statistics Trie tree letter number CNT, set the longest word length is maxlen, then the answer is 2*cnt+n-maxlen.

CNT to multiply by 2, because the printing is also a delete after the equivalent of each word went two times.

Plus n, is the number of times to print.

Minus MaxLen is because the last word doesn't need to be deleted.

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.