Processing math: 100%
Longest common subsequence - MarisaOJ: Marisa Online Judge

Longest common subsequence

Time limit: 1000 ms
Memory limit: 256 MB
You are given 2 arrays A,B both of n integers, find the longest common subsequence (LCS) of A and B. In other words, find the largest k that there exist some indices i1<i2<...<ik and j1<j2<...<jk that: Ai1=Bj1 Ai2=Bj2 ... Aik=Bjk ### Input - The first line contains an integer n. - The second line contains n integers Ai. - The third line contains n integers Bi. ### Output - Print the length of the LCS. ### Constraints - 1≤n≤1000 - 1≤Ai,Bi≤109. ### Example Input: 412343421 Output: 2 Note: The LCS is (3,4).