Acm hdu 3460 external ent printer (simple question)

Source: Internet
Author: User
Login ent printer

Time Limit: 2000/1000 MS (Java/others) memory limit: 131072/65536 K (Java/Others)
Total submission (s): 704 accepted submission (s): 309

Problem descriptionthe contest is beginning! While preparing the contest, ISEA wanted to print the teams 'names separately on a single paper.
Unfortunately, what ISEA cocould find was only an internal ent printer: So external that you can't believe it, it only had three kinds 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 was empty in the beginning, ISEA must use the three operations to print all the teams 'name, not necessarily in 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 are stilling in the printer, you may 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 are several test cases in the input.

Each test case 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 input2
Freeradiant
Freeopen

Sample output21

Hint

The sample's operation is:
F-r-e-o-p-e-n-print-Del-r-a-d-I-a-n-t- print

 

Authorisea @ whu

Source2010 ACM-ICPC multi-university training Contest (3) -- host by whu

Recommendzhouzeyong
 # Include  <  Iostream  > 
# Include < String . H >
# Include < Algorithm >
# Include < Stdio. h >
Using Namespace STD;
String W [ 10005 ];
Int Calc ( String A, String B)
{
Int I;
For (I = 0 ; I < A. Length () && I < B. Length () && A [I] = B [I]; I ++ );
Return A. Length () - I + B. Length () - I;
}
Int Main ()
{
Int N, I;
While (Scanf ( " % D " , & N) ! = EOF)
{
For (I = 0 ; I < N; I ++ ) CIN > W [I];
Sort (W, W + N );
Int Sum = W [ 0 ]. Length () + 1 ;
Int Max = W [ 0 ]. Length ();
For (I = 1 ; I < N; I ++ )
{
Sum + = Calc (W [I], W [I - 1 ]) + 1 ;
If (W [I]. Length () > Max)
Max = W [I]. Length ();
}
Printf ( " % D \ n " , Sum + W [n - 1 ]. Length () - Max );
}
Return 0 ;
}

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.