#P1032. [NOIP 2002 提高组] 字串变换(疑似错题)
[NOIP 2002 提高组] 字串变换(疑似错题)
Description
You are given two strings and a set of string transformation rules (at most rules), of the form:
- .
- .
The meaning of the rules is: in , a substring can be transformed into , can be transformed into .
For example: , ,
with the transformation rules:
- , , .
Then can be transformed into through a sequence of transformations:
- $\texttt{abcd}\rightarrow\texttt{xud}\rightarrow\texttt{xy}\rightarrow\texttt{xyz}$.
A total of transformations are performed to transform into .
Input Format
The first line contains two strings .
Each of the following lines contains two strings , representing one transformation rule.
Output Format
If can be transformed into within steps (inclusive), output the minimum number of steps; otherwise, output NO ANSWER!.
abcd xyz
abc xu
ud y
y yz
3
Hint
For of the testdata, the maximum length of all strings is .
Source: NOIP 2002 Senior, Problem 2.
Translated by ChatGPT 5
京公网安备 11011102002149号