#P5484. [JLOI2011] 基因补全

    ID: 6230 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划 DP高精度2011各省省选吉林

[JLOI2011] 基因补全

Problem Description

In biology class, we learned that bases make up DNADNA (deoxyribonucleic acid). They can be represented by the uppercase letters A,C,T,GA, C, T, G, where AA always pairs with TT, and CC always pairs with GG. Two base sequences can match each other if and only if they have the same length, and at every position, the two bases can pair with each other. For example, ACGTCACGTC can and only can pair with TGCAGTGCAG.

A relatively shorter base sequence can be made to pair with a relatively longer base sequence by inserting bases at any positions in the shorter sequence. Different insertion positions or different numbers of inserted bases are considered different completion plans.

Now you are given two base sequences SS and TT, with lengths nn and mm respectively (nmn \geq m). Find how many completion plans there are in total.

Input Format

The input has three lines.
The first line contains two integers nn and mm, representing the lengths of the base sequences.
The second line contains nn characters, representing the base sequence SS.
The third line contains mm characters, representing the base sequence TT.
The characters in both sequences are only the 44 uppercase letters A,C,G,TA, C, G, T.

Output Format

Output one line containing the number of completion plans.

10 3
CTAGTAGAAG
TCC
4

Hint

Sample explanation:
The 44 completion plans for TCCTCC (characters in parentheses are the inserted bases):
(GA)TC(AT)C(TTC)(GA)TC(AT)C(TTC)
(GA)TC(ATCTT)C(GA)TC(ATCTT)C
(GA)T(CAT)C(TT)C(GA)T(CAT)C(TT)C
(GATCA)TC(TT)C(GATCA)TC(TT)C

Constraints:
For 30%30\% of the testdata, n1000,m2n \leq 1000, m \leq 2.
For 50%50\% of the testdata, n1000,m4n \leq 1000, m \leq 4.
For 100%100\% of the testdata, n2000,mnn \leq 2000, m \leq n.

Translated by ChatGPT 5