TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description

The longest common subsequence problem (LCS) is finding the longest subsequence common to all sequences in a set of sequences (often just two). It is a classic computer science problem, the basis of diff, and has applications in bioinformatics.
Given a set of sequences, output the length of the LCS of these sequences.

Input Format

Each test case starts by a number n (1<=n<=100), denoting the number of sequences. Following are n sequences, each on a line. These sequences contain lower-case letters only and have a maximum length of 15.

Output Format

For each test case, output the length of the LCS on a line by itself.

Sample Input 1

2
abcd
dcba
3
abcdefg
deiscool
imde

Sample Output 1

1
2

Hints

In case n=2, there is a dynamic programming solution. But now n may be larger than 2.

Problem Source

Migrated from old NTUJ.

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 10000 65536 200