问题3465--Periodic, My Dear Watson

3465: Periodic, My Dear Watson

[命题人 : ]
时间限制 : 3.000 sec  内存限制 : 64 MB

题目描述

Given the periodic table and a series of words, determine whether the word can be formed using the elements in the periodic table. If there are multiple ways of doing so, select the one with the fewest number of required elements. If multiple options use the same minimal number of elements, sum the atomic numbers (atomic numbers are implied by the order in which the elements are read in) used for each option, and select the one with the smallest value. If there are still multiple, then there's probably no point, as it is most likely too obvious, so in these cases, simply print “Too Obvious” for the given word. An 'element' always starts with a capital letter followed by zero or more lower case letters.

输入

Input will begin with a line containing a single integer, N representing the number of cases to process. Each case will being with a line with a single integer, O, representing the number of symbols in the case. The next O lines will contain one element per line. The next line will contain a single integer, P representing the number of words to process in this case. The next P lines contain one word each. O and P as well as the length of any element or name will be less than 5000.

<Number of cases>
<number of elements>
<elements...>
<number of words>
<words...>
 

输出

If a given word has a deterministic answer based on the periodic table provided and the above stated rules, print the case number and the series of elements used, forming the word, but with square brackets around them to indicate the elements. One example output line might be: “[Ba][Na][Na]”

样例输入 Copy

1
4
Ba
Na
N
A
2
banana
nan

样例输出 Copy

[Ba][Na][Na]
[Na][N]

来源/分类