XMEN - X-MEN
Dr. Charles Xavier is trying to check the correlation between the DNA samples of Magneto and Wolverine. Both the DNAs are of length N, and can be described by using all integers between 1 to N exactly once. The correlation between two DNAs is defined as the Longest Common Subsequence of both the DNAs.
Help Dr. Xavier find the correlation between the two DNAs.
First line of input contains number of Test Cases T.
ach test case starts with an integer N, size of DNA.
Next two lines contains N integers each, first line depicting the sequence of Magneto's DNA and second line depicting Wolverine's DNA.
For each test case print one integer, the correlation between the two DNAs.
Sample Input :
2 2 1 2 2 1 3 1 2 3 1 3 2
Sample Output :
1 ≤ T ≤ 10
1 ≤ N ≤ 100000
Nice problem to practice n lg n LIS. Thank you. What's the number of this problem?Last edit: 2017-10-13 04:04:18
it is constantly throwing runtime error i don't know why pls any suggestion
can someone clarify how mapping guarantees the optimal solution ?
nlogk solution is acceptable ... This problem is not LCS .. It's actually a LIS problem .. All u need to do , u just need to convert it into a lis problem .. (Converting is not too much difficult . just think one DNA as index and other DNA as element , now map them )
The O(n^2) Dynamic Programming solution gave TLE.
The problem statement doesn't clear if it's LCS between digits or each number is considered as individual symbol?
Longest Common/ Increasing Subsequence ( DP )Last edit: 2015-01-26 08:34:05