#P2268. [HNOI2002] DNA 分子的最佳比对

[HNOI2002] DNA 分子的最佳比对

Description

DNA\operatorname{DNA} molecules are carriers of human genetic information, indirectly guiding protein synthesis. A DNA\operatorname{DNA} molecule is a long chain composed of four nucleotides: adenine nucleotide (denoted by A\operatorname{A}), guanine nucleotide (denoted by G\operatorname{G}), cytosine nucleotide (denoted by C\operatorname{C}), and thymine nucleotide (denoted by T\operatorname{T}). By convention, a {A,T,C,G}\{\operatorname{A,T,C,G}\}-alphabet string is used to represent a DNA\operatorname{DNA} sequence, such as CGTTAGA\operatorname{CGTTAGA}.

During biological evolution, DNA\operatorname{DNA} molecules may undergo various mutations. These mutations change genetic information, enabling species differentiation and forming biological diversity.

There are three main types of mutations:

  1. Inserting a new nucleotide into a DNA\operatorname{DNA} sequence,
  2. Deleting a nucleotide from a DNA\operatorname{DNA} sequence,
  3. Substituting one nucleotide in the DNA\operatorname{DNA} sequence with another.

An alignment of two DNA\operatorname{DNA} sequences is an arrangement that places the two sequences so that identical nucleotides appear at the same positions. If the nucleotides at the same position differ, that difference is attributed to one of the three types of mutations. For example, for two DNA\operatorname{DNA} sequences T1=ATCAGT_1 =\operatorname{ATCAG}, T2=ACTAGT_2 =\operatorname{ACTAG}, one possible alignment is as follows (where - denotes a gap):

Alignment 1:

T1T_1 T2T_2
A\text A
T\text T -
C\text C
- T\text T
A\text A
G\text G

Another possible alignment is:

Alignment 2:

T1T_1 T2T_2
A\text A
T\text T C\text C
C\text C T\text T
A\text A
G\text G

The more identical nucleotide pairs the two DNA\operatorname{DNA} sequences have at the same positions, the more similar they are, indicating functional similarity and phylogenetic relatedness.

The scoring rules for an alignment of two DNA\operatorname{DNA} sequences are as follows:

  1. If the nucleotides at the same position are identical, score 11 point.
  2. If the nucleotides at the same position are different, score 00 points.
  3. If one sequence has a nucleotide at some position while the other has - at that position, score 2-2 points.

For example, the score of Alignment 1 is 00 points, and the score of Alignment 2 is 33 points.

The task is: Given two DNA\operatorname{DNA} sequences, find an alignment that maximizes the score.

Input Format

The input consists of two lines.

The first line is the DNA\text{DNA} sequence T1T _ 1, and the second line is the DNA\text{DNA} sequence T2T _ 2. The length of each sequence does not exceed 10001000. The letters in the sequences are lowercase or uppercase English letters.

Output Format

Output the maximum score found.

Atcag
Actag

3

Hint

Translated by ChatGPT 5