Longest Common Subsequence
시간 제한2초메모리 제한256 MB
값이 1, 2, 3뿐인 두 수열이 주어질 때, 비감소 조건을 만족하는 가장 긴 공통 부분 수열의 길이를 구한다.
문제
Chiaki has two sequences and . She would like to find their longest common subsequence such that .
입력
There are multiple test cases. The first line of input contains an integer , indicating the number of test cases. For each test case:
The first line contains two integers and (): the lengths of two sequences.
The second line contains integers ().
The third line contains integers ().
It is guaranteed that the sum of in all test cases does not exceed .
출력
For each test case, output a single integer : the length of the longest common subsequence such that .