当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

3633: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 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”

  1. Get GT......... by copying and reversing "TG" from S.
  2. Get GTAC....... by copying "AC" from S.
  3. Get GTAC...TA.. by copying "TA" from the partial T.
  4. Get GTAC...TAAT by copying and reversing "TA" from the partial T.
  5. Get GTACAATTAAT by copying "AAT" from the partial T.
输入解释

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 for each test case the number of copy operations needed to create T from S, or "impossible" if it cannot be done.

输入样例
5
ACGT
GTAC
A
C
ACGT
TGCA
ACGT
TCGATCGA
A
AAAAAAAAAAAAAAAAAA
输出样例
2
impossible
1
4
6

该题目是Virtual Judge题目,来自 北京大学POJ

题目来源 Nordic 2007

源链接: POJ-3633

最后修改于 2020-10-29T07:06:30+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 65536