#P4059. [Code+#1] 找爸爸
[Code+#1] 找爸爸
Description
Xiao A has been looking for his own father recently. How? By DNA matching.
Xiao A has his own method for comparing DNA sequences. The goal is to maximize the similarity score between two DNA sequences. The steps are as follows:
- Given two DNA sequences, the first of length and the second of length .
- Insert any number of gaps at any positions in the two sequences so that the two strings have the same length.
- Match position by position. If at a position neither character is a gap, let the first be and the second be , then their similarity is defined as . For any maximal contiguous block of gaps of length in either sequence, we define its similarity as .
The final similarity score of the two sequences is the sum of all values plus the similarity of all maximal gap blocks.
Now Xiao A has, by some mysterious means, obtained a segment of Xiao B’s DNA sequence. He asks you to compute the maximum similarity score between Xiao A’s DNA sequence and Xiao B’s DNA sequence.
Input Format
The first line contains a string representing Xiao A’s DNA sequence. The second line contains a string representing Xiao B’s DNA sequence. The next lines each contain integers separated by spaces, representing the array in the following order.
d(A,A) d(A,T) d(A,G) d(A,C)
d(T,A) d(T,T) d(T,G) d(T,C)
d(G,A) d(G,T) d(G,G) d(G,C)
d(C,A) d(C,T) d(C,G) d(C,C)
The last line contains two positive integers separated by spaces, as described above.
Output Format
Output a single line: the maximum similarity score of the two sequences.
ATGG
ATCC
5 -4 -4 -4
-4 5 -4 -4
-4 -4 5 -4
-4 -4 -4 5
2 1
4
Hint
Sample explanation.
First, pad the sequences as follows (“-” denotes a gap):
ATGG--
AT--CC
Then the sum of all is . The sum of the similarity of all maximal contiguous gap blocks is . The total is , which can be verified to be the maximum similarity.
For all test points, , , , and each sequence contains only the four characters .
| Test point ID | range | Special notes |
|---|---|---|
| No special requirements. | ||
| ^ | ||
| ^ | ||
| Sequences contain only one type of character. | ||
| ^ | No special requirements. | |
| ^ | ||
From CodePlus 2017 November Contest, proudly presented by the Student Algorithm and Competition Association, Department of Computer Science and Technology, Tsinghua University.
Credit: Idea/Lu Zhengrong; Problem setter/Lu Zhengrong; Tester/He Haotian.
Git Repo: https://git.thusaac.org/publish/CodePlus201711
Thanks to Tencent for supporting this contest.
Translated by ChatGPT 5
京公网安备 11011102002149号