#P1624. 单词缩写
单词缩写
Description
Shushu noticed that many computer terms are abbreviations. For example, GDB is the abbreviation of Gnu DeBug. However, sometimes an abbreviation may have multiple possible full forms. For example, LINUX can be understood as:
- LINus’s UniX
- LINUs’s miniX
- Linux Is Not UniX
Now Shushu gives an abbreviation and a fixed full form (several words separated by spaces). Some words in the full form may be invalid and should be ignored. A valid abbreviation requires that:
- Each valid word contributes at least one character that appears in the abbreviation.
- The selected letters must appear in order in the full form (within each word and across words).
For the given abbreviation and full form, how many interpretations are there? An interpretation is defined by the positions of the letters chosen in each valid word. If any letter’s position differs, they are considered different interpretations.
Input Format
The first line contains an integer , the number of invalid words.
The next lines each contain one invalid word, consisting of lowercase letters.
Then follow multiple queries. Each query provides an abbreviation (uppercase letters only) followed by a full form. Input ends with a line containing LASTCASE.
Output Format
For each query, first output the abbreviation. If the abbreviation is not valid, output is not a valid abbreviation; otherwise, output can be formed in i ways (where is the number of interpretations).
2
and
of
ACM academy of computer makers
RADAR radio detection and ranging
LAST CASE
ACM can be formed in 2 ways
RADAR is not a valid abbreviation
Hint
Constraints
For all testdata, , the length of each string does not exceed , the number of queries does not exceed , and the number of interpretations does not exceed .
Translated by ChatGPT 5
京公网安备 11011102002149号