#P13290. [GCJ 2013 #1B] Garbled Email
[GCJ 2013 #1B] Garbled Email
题目描述
Gagan just got an email from her friend Jorge. The email contains important information, but unfortunately it was corrupted when it was sent: all of the spaces are missing, and after the removal of the spaces, some of the letters have been changed to other letters! All Gagan has now is a string of lower-case characters.
You know that the email was originally made out of words from the dictionary described below. You also know the letters were changed after the spaces were removed, and that the difference between the indices of any two letter changes is not less than 5. So for example, the string "code jam" could have become "codejam", "dodejbm", "zodejan" or "cidejab", but not "kodezam" (because the distance between the indices of the "k" change and the "z" change is only 4).
What is the minimum number of letters that could have been changed
The dictionary contains words of at least 1 and at most 10 lower-case characters and is given at the start of the input file. It is not a dictionary from any natural language, though it does contain some English words. The dictionary is the same for all test cases in a single input file. The dictionary is given in lexicographically increasing order and does not contain duplicate words.
输入格式
The first line of the input gives the number of words in the dictionary, . Each of the next lines contains a string of lower-case characters a-z representing a word in the dictionary. The next line of the input gives the number of test cases, . test cases follow. Each test case consists of a single line containing a string , consisting of lower-case characters a-z.
输出格式
For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1) and y is the minimum number of letters that could have been changed in order to make .
9
aabea
bobs
code
in
jam
oo
operation
production
system
4
codejam
cxdejax
cooperationaabea
jobsinproduction
Case #1: 0
Case #2: 2
Case #3: 1
Case #4: 1
提示
Sample Explanation
"code" and "jam" both appear in the dictionary. Although "cooperation" is an English word, it doesn't appear in the dictionary; "aabea" does.
Note that to make the sample case visible in the problem statement, the size of the dictionary in the sample case does not satisfy the limits.
Limits
- .
- Each word in the dictionary contains at least 1 and at most 10 lower-case characters.
- The dictionary is sorted in lexicographically increasing order.
- The dictionary does not contain duplicate words.
- The total number of characters in the dictionary is .
- is valid: it is possible to make it using the method described above.
Small dataset (12 Pts, Test set 1 - Visible)
- Time limit:
303 seconds. - .
- .
Large dataset (24 Pts, Test set 2 - Hidden)
- Time limit:
606 seconds. - .
- .