Common scores

Two friends, Arthur and Bob, are playing computer games, and they have
decided to store their scores. When they stop playing, Arthur and Bob
want to determine the length of the maximum subsequence of scores that
they have in common.

For instance, if the scores of Arthur are [8, 12, 6, 9, 2], and those of
Bob are [12, 6, 8, 2], then the maximum subsequence that they have in
common is [12, 6, 2], which has length 3. Note that a subsequence does
not have to be made up of consecutive elements, but we must preserve the
order of the scores.

Input

Input consists of several cases. Each case begins with two numbers
0 ≤ M ≤ 1000 and 0 ≤ N ≤ 1000, representing the length of the
subsequences of Arthur and Bob, respectively. Follow the M numbers of
Arthur, and the N numbers of Bob. All the numbers are natural.

Output

For every case, print the length of the longest common subsequence.

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T12:08:27.096Z

© Jutge.org, 2006–2026.
https://jutge.org
