Croc Champ 2012 - Round 2
D
Hyper String
Codeforces
2500
原题
← CE →
翻译中…

Paul Erdős's prediction came true. Finally an alien force landed on the Earth. In contrary to our expectation they didn't asked the humans to compute the value of a Ramsey number (maybe they had solved it themselves). They asked another question which seemed as hard as calculating Ramsey numbers. Aliens threatened that if humans don't solve this problem in less than 2 hours they will destroy the Earth.

翻译中…

Before telling the problem they introduced the concept of Hyper Strings. A Hyper String is made by concatenation of some base strings. Suppose you are given a list of base strings $*b*_{1}, *b*_{2}, ..., *b*_{*n*}$. Now the Hyper String made from indices list $*i*_{1}, *i*_{2}, ..., *i*_{*m*}$ is concatenation of base strings $*b*_{*i*_{1}}, *b*_{*i*_{2}}, ..., *b*_{*i*_{*m*}}$. A Hyper String can be very large and doing operations on it is very costly for computers.

翻译中…

The aliens asked humans to compute the length of the longest common sub-sequence of a Hyper String $*t*$ with a string $*s*$.

翻译中…

Input

翻译中…

The first line of input contains the single integer $*n*$ ($1 ≤ *n* ≤ 2000$) — the number of base strings.

翻译中…

The next $*n*$ lines contains values of base strings. Each base string is made of lowercase Latin letters. A base string cannot be empty string and the sum of lengths of all $*n*$ base strings doesn't exceed $10^{6}$.

翻译中…

The next line contains the single integer $*m*$ ($1 ≤ *m* ≤ 2000$) — the number of base strings in the given Hyper String $*t*$.

翻译中…

The next line contains $*m*$ space-separated integer numbers $*i*_{1}, *i*_{2}, ..., *i*_{*m*}$ ($1 ≤ *i*_{*j*} ≤ *n*$) — the indices of base strings in the Hyper String $*t*$.

翻译中…

The last line contains a non-empty string $*s*$. String $*s*$ is made of lowercase Latin letters and its length is no more than $2000$ characters.

翻译中…

Output

翻译中…

Print the length of longest common sub-sequence of Hyper String $*t*$ and string $*s*$. If there is no common sub-sequence print 0.

翻译中…

Note

翻译中…

The length of string $*s*$ is the number of characters in it. If the length of string $*s*$ is marked as $|*s*|$, then string $*s*$ can be represented as $*s* = *s*_{1}*s*_{2}... *s*_{|*s*|}$.

翻译中…

A non-empty string $*y* = *s*[*p*_{1}*p*_{2}... *p*_{|*y*|}] = *s*_{*p*_{1}}*s*_{*p*_{2}}... *s*_{*p*_{|*y*|}}$ ($1 ≤ *p*_{1} < *p*_{2} < ... < *p*_{|*y*|} ≤ |*s*|$) is a subsequence of string $*s*$. For example, "coders" is a subsequence of "codeforces".

翻译中…

样例

Input #1
2
cba
dgh
2
1 2
aedfhr
Output #1
3
InputCopy OutputCopy
Input #2
2
b
a
5
1 2 1 2 1
aaa
Output #2
2
InputCopy OutputCopy
题目信息
题号
176D
时间限制
2 s
内存限制
256 MB
标签
动态规划

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。