Genomes
Time limit1sMemory limit128 MB
Find the length of the longest common subsequence of up to 20 permutations of size up to 500.
- Level
Medium6 of 10
- Topics
- Graph, Topological sort, Dynamic programming
- Solved
- No attempts yet
Problem
Biologists working in comparative genetics are looking for gene sequences that are conserved across a set of species.
Let the set denote the genes, so that each number corresponds to one gene. Every species is described by a permutation of that gives the ordering of its genes. A gene sequence is a conserved gene sequence for a set of species if it is a subsequence (not necessarily contiguous) of the gene ordering of every one of those species.
Write a program that reads the gene orderings from standard input, determines the length of the longest conserved sequence, and writes that length to standard output.
Input
The first line contains two integers and separated by a single space, with and . Here is the number of genes and is the number of species. Each of the next lines contains the genome of one species, written as a permutation of with the numbers separated by single spaces.
Output
Print a single integer equal to the length of the longest conserved gene sequence.