编程介的小学生 2017-10-02 00:38 采纳率: 20.5%
浏览 937
已采纳

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

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-10-17 17:08
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 求数学坐标画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站