#P6701. [POI 1997] Genotype
[POI 1997] Genotype
Background
Genotype is a unique gene string.
Problem Description
We can use uppercase English letters A-Z to describe a Genotype, where each letter represents one gene.
We define a “split” rule, consisting of three uppercase letters , meaning that can “split” into .
Now you are given “split” rules and Genotypes. Determine whether each Genotype can be obtained from a specific string consisting only of the uppercase letter S by applying the “split” rules. If it can, output the minimum possible length of that specific string. If it cannot, output NIE.
Input Format
The first line contains an integer , the number of “split” rules.
The next lines each contain three uppercase letters , representing one “split” rule.
The next line contains an integer , the number of given Genotypes.
The next lines each contain several uppercase letters, representing one Genotype.
Output Format
Output lines:
- If no specific string can produce this Genotype by applying the “split” rules, output
NIE. - Otherwise, output the minimum length of such a 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