#P4584. [FJOI2015] 带子串包含约束LCS问题
[FJOI2015] 带子串包含约束LCS问题
Description
The longest common subsequence problem with substring inclusion constraints can be stated as follows.
Given two sequences and of lengths and , respectively, and a set of substring inclusion constraints.
There are strings in , , where the length of string is , . The problem is to find a longest common subsequence of and that contains every string in the constraint set as its substring.
For example, if the given sequences are and , and the constraint set is , then the subsequence actacct is an unconstrained LCS of and , while a longest common subsequence that contains all strings in as substrings is atact. In this problem, please pay special attention to the difference between substring and subsequence. The substring of a string is a string of the form ’, where , . For example, if , then bcd is a substring of , while bce is a subsequence of but not a substring of .
Design an algorithm to find a longest common subsequence of the given sequences and that satisfies the substring inclusion constraints .
Input Format
- The first line contains positive integers , , , with , , . Here and are the lengths of the given sequences and , respectively. The value is the number of strings in the constraint set .
- The second line contains integers , with , , which are the lengths of the strings in the constraint set .
- The third and fourth lines give the sequences and .
- The next lines each contain one string .
Output Format
Output the length of a longest common subsequence of and that satisfies the substring inclusion constraints .
10 10 2
3 4
actaagacct
gacctacctc
ata
tact
5
Hint
The strings contain only uppercase and lowercase letters.
Translated by ChatGPT 5
京公网安备 11011102002149号