编程介的小学生 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
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services