编程介的小学生 2019-09-22 23:00 采纳率: 20.5%
浏览 155

DNA的复制的算法,Copying DNA

Description

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 S from the alphabet {A,C,G,T}, find the minimal number of copy operations needed to create another string T. You may reverse the strings you copy, and copy both from S and the pieces of your partial T. You may put these pieces together at any time. You may only copy contiguous parts of your partial T, and all copied strings must be used in your final T. 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.
Input

The first line of input gives a single integer, 1 ≤ t ≤ 100, the number of test cases. Then follow, for each test case, a line with the string S of length 1 ≤ m ≤ 18, and a line with the string T of length 1 ≤ n ≤ 18.

Output

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

Sample Input

5
ACGT
GTAC
A
C
ACGT
TGCA
ACGT
TCGATCGA
A
AAAAAAAAAAAAAAAAAA
Sample Output

2
impossible
1
4
6
Source

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料
    • ¥15 使用R语言marginaleffects包进行边际效应图绘制
    • ¥20 usb设备兼容性问题
    • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
    • ¥15 安装svn网络有问题怎么办