F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

LCS

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1901    Accepted Submission(s): 958


Problem Description
You are given two sequence $\{a_1, a_2, ..., a_n\}$ and $\{b_1,b_2, ... ,b_n\}$. Both sequences are permutation of $\{1,2,...,n\}$. You are going to find another permutation $\{p_1,p_2,...,p_n\}$ such that the length of LCS (longest common subsequence) of $\{a_{p_1},a_{p_2},...,a_{p_n}\}$ and $\{b_{p_1},b_{p_2},...,b_{p_n}\}$ is maximum.
 

Input
There are multiple test cases. The first line of input contains an integer $T$, indicating the number of test cases. For each test case:

The first line contains an integer $n (1 \le n \le 10^5)$ - the length of the permutation. The second line contains $n$ integers $a_1,a_2,...,a_n$. The third line contains $n$ integers $b_1,b_2,...,b_n$.

The sum of $n$ in the test cases will not exceed $2 \times 10^6$.
 

Output
For each test case, output the maximum length of LCS.
 

Sample Input
2 3 1 2 3 3 2 1 6 1 5 3 2 6 4 3 6 2 4 5 1
 

Sample Output
2 4
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-12-04 00:44:26, Gzip enabled