#P2581. [ZJOI2005] Genotype
[ZJOI2005] Genotype
Description
We can use uppercase English letters to describe a Genotype, where each letter represents a gene.
Define a "split" rule as a triple of uppercase letters , meaning can "split" into .
Given "split" rules and Genotypes, determine whether each Genotype can be obtained from a specific string that consists only of the uppercase letter by applying the "split" rules. If it is possible, output the minimal length of that specific string; otherwise, output NIE.
Input Format
The first line contains an integer , the number of "split" rules.
Each of the next lines contains three uppercase letters representing one "split" rule.
The next line contains an integer , the number of given Genotypes.
Each of the next lines contains a string of uppercase letters representing a Genotype.
Output Format
lines:
- If no such specific string can produce the Genotype via the "split" rules, output
NIE. - If there is such a specific string, output the minimal length of that specific string.
6
SAB
SBC
SAA
ACA
BCC
CBC
3
ABBCAAABCA
CCC
BA
3
1
NIE
Hint
Constraints
For of the testdata, , and the maximum length of a Genotype is .
Translated by ChatGPT 5
京公网安备 11011102002149号