首页 > 试题广场 >

Longest Common Subsequence

[编程题]Longest Common Subsequence
Niuniu has recently learned LCS(Longest Common Subsequence) of two sequences.
Now he wants to know the LCS of four sequences.
Given 4 sequences {ai}, {bi}, {ci}, {di}.
Please find the longest common subsequence.

输入描述:
The first line contains one integer, which is n.
The second line contains n integers, which is the sequence {ai}.
The third line contains n integers, which is the sequence {bi}.
The fourth line contains n integers, which is the sequence {ci}.
The fifth line contains n integers, which is the sequence {di}.

1 <= n <= 10000
1 <= ai <= n
Any number appears in {ai} at most 2 times.
1 <= bi <= n
Any number appears in {bi} at most 2 times.
1 <= ci <= n
Any number appears in {ci} at most 2 times.
1 <= di <= n


输出描述:
You should output one integer, which is the length of the LCS.
示例1

输入

5
1 2 1 2 3
1 2 3 1 2
3 1 2 1 2
1 2 1 2 1

输出

4

这道题你会答吗?花几分钟告诉大家答案吧!