CF176D.Hyper String

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 b1,b2,...,bnb_{1},b_{2},...,b_{n} . Now the Hyper String made from indices list i1,i2,...,imi_{1},i_{2},...,i_{m} is concatenation of base strings bi1,bi2,...,bimb_{i1},b_{i2},...,b_{im} . 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 tt with a string ss .

输入格式

The first line of input contains the single integer nn ( 1<=n<=20001<=n<=2000 ) — the number of base strings.

The next nn 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 nn base strings doesn't exceed 10610^{6} .

The next line contains the single integer mm ( 1<=m<=20001<=m<=2000 ) — the number of base strings in the given Hyper String tt .

The next line contains mm space-separated integer numbers i1,i2,...,imi_{1},i_{2},...,i_{m} ( 1<=ij<=n1<=i_{j}<=n ) — the indices of base strings in the Hyper String tt .

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

输出格式

Print the length of longest common sub-sequence of Hyper String tt and string ss . If there is no common sub-sequence print 0.

输入输出样例

  • 输入#1

    2
    cba
    dgh
    2
    1 2
    aedfhr
    

    输出#1

    3
    
  • 输入#2

    2
    b
    a
    5
    1 2 1 2 1
    aaa
    

    输出#2

    2
    

说明/提示

The length of string ss is the number of characters in it. If the length of string ss is marked as s|s| , then string ss can be represented as s=s1s2... sss=s_{1}s_{2}...\ s_{|s|} .

A non-empty string y=s[p1p2... py]=sp1sp2... spyy=s[p_{1}p_{2}...\ p_{|y|}]=s_{p1}s_{p2}...\ s_{p|y|} ( 1<=p_{1}<p_{2}<...<p_{|y|}<=|s| ) is a subsequence of string ss . For example, "coders" is a subsequence of "codeforces".

首页