#P1140. 相似基因

相似基因

Description

The similarity between two genes is computed as follows:

For two given genes, for example AGTGATG and GTTAG, align their bases with each other. Of course, you may insert some gap bases - in between, for example:

$$\def\arraystretch{1.5} \begin{array}{|c|c|c|c|c|c|c|c|} \hline \tt A & \tt G & \tt T & \tt G & \tt A & \tt T & \texttt - & \tt G \\ \hline \texttt - & \tt G & \tt T & \texttt - & \texttt - & \tt T & \texttt A & \tt G \\ \hline \end{array}$$

Then the similarity between the two genes can be described as the sum of pairwise base similarities, as shown in the following table:

$$\def\arraystretch{1.5} \begin{array}{ |c|c|c|c|c|c|} \hline & \tt A & \tt C & \tt G & \tt T & \texttt - \\ \hline \tt A & 5 & -1 & -2 & -1 & -3\\ \hline \tt C & -1 & 5 & -3 & -2 & -4 \\\hline \tt G & -2 & -3 & 5 & -2 & -2 \\\hline \tt T & -1 & -2 & -2 & 5 & -1 \\\hline \texttt - & -3 & -4 & -2 & -1 & * \\\hline \end{array}$$

Thus the similarity is: (3)+5+5+(2)+(3)+5+(3)+5=9(-3)+5+5+(-2)+(-3)+5+(-3)+5=9. Since the alignment between two genes is not unique, for example:

$$\def\arraystretch{1.5} \begin{array}{|c|c|c|c|c|c|c|} \hline \tt A & \tt G & \tt T & \tt G & \tt A & \tt T & \tt G \\ \hline \texttt - & \tt G & \tt T & \texttt T & \texttt A & \texttt - & \tt G \\ \hline \end{array}$$

The similarity is: (3)+5+5+(2)+5+(1)+5=14(-3)+5+5+(-2)+5+(-1)+5=14. Define the similarity between two genes as the maximum similarity among all alignments.

Input Format

There are two lines. Each line first contains an integer nn, representing the length of the gene sequence; after a space is a gene sequence that contains only the four letters A,C,G,T\verb!A!,\verb!C!,\verb!G!,\verb!T!. 1n1001 \le n \le 100.

Output Format

Only one line: the similarity of the input genes.

7 AGTGATG
5 GTTAG

14

Hint

Translated by ChatGPT 5