#2485. Pku3633 Copying DNA

Pku3633 Copying DNA

题目描述

Evolution is a seemingly random process which works in a way which resembles certain approaches we use to get approximate solutions to hard combinatorial problems.You are now to do something completely different.
Given a DNA string SS from the alphabet A,C,G,T\text{A,C,G,T},find the minimal number of copy operations needed to create another string TT.You may reverse the strings you copy,and copy both from SS and the pieces of your partial TT.You may put these pieces together at any time.You may only copy contiguous parts of your partial TT,and all copied strings must be used in your final TT

Example:From S={ACTG} create T={GTACTATTATA}
Get GT......... by copying and reversing 「TG」 from S.
Get GTAC....... by copying 「AC」 from S.
Get GTAC...TA.. by copying 「TA」 from the partial T.
Get GTAC...TAAT by copying and reversing 「TA」 from the partial T.
Get GTACAATTAAT by copying 「AAT」 from the partial T.

给你两个字符串 SSTT,要求你用尽量少的步数从 SS 构造出 TT。每一步你可以做以下操作:从 SS 或者 TT 的片段中拷贝一个字符串,然后可以将这个字符串反向,然后你得到一个片段。片段可以随时合并,但不能拆分,并且所有的片段都要使用。从 TT 中拷贝字符串只能从一个片段中拷贝。求你最少需要的步数。两个串的字符数 18\le 18

输入格式

The first line of input gives a single integer,t,the number of test cases.
Then follow,for each test case,a line with the string SS of length mm and a line with the string TT of length nn

输出格式

Output for each test case the number of copy operations needed to create TT from SS,or impossible if it cannot be done.

5
ACGT
GTAC
A
C
ACGT
TGCA
ACGT
TCGATCGA
A
AAAAAAAAAAAAAAAAAA
2
impossible
1
4
6

数据规模与约定

100%100\% 的数据满足:1t1001 \le t \le 1001m,n181 \le m,n \le 18