#P4303. [AHOI2006] 基因匹配
[AHOI2006] 基因匹配
Description
Kaka dreamed last night that he and Keke arrived on another planet. On this planet, organisms have DNA sequences formed by countless types of bases (on Earth there are only types). Even stranger, each type of base appears exactly times in any given DNA sequence. Thus, if a DNA sequence consists of distinct types of bases, its length must be .
After waking up, Kaka told Keke about this strange dream. Keke has been studying the gene matching problem in bioinformatics, so he decided to write a simple DNA matching program for organisms on this strange planet.
To describe the principle of gene matching, we first define the concept of a subsequence: if we arbitrarily pick some bases (characters) from a DNA sequence (string) and arrange them in the same order as in to form a new string , then is called a subsequence of . For two DNA sequences and , if there exists a sequence that is a subsequence of both and , then is called a common subsequence of and .
Given two DNA sequences and , the maximum match is defined as the length of the longest common subsequence of and .
[Task] Write a program to:
- Read two DNA sequences of equal length from the input file.
- Compute their maximum match.
- Print your result to the output file.
Input Format
The first line contains an integer , meaning that a certain organism on this planet uses distinct types of bases, numbered by the integers .
The next two lines each describe a DNA sequence: each contains integers in the range , and every integer appears exactly times in the corresponding sequence.
Output Format
Output a single integer: the maximum match of the two DNA sequences.
2
1 1 1 1 1 2 2 2 2 2
1 1 1 2 2 2 2 2 1 1
8
Hint
.
Translated by ChatGPT 5
京公网安备 11011102002149号