#P4608. [FJOI2016] 所有公共子序列问题
[FJOI2016] 所有公共子序列问题
Description
A subsequence of a given sequence is obtained by deleting some elements from that sequence. Precisely, given a sequence , another sequence is a subsequence of if there exists a strictly increasing index sequence such that for all we have .
For example, the sequence is a subsequence of the sequence , with the corresponding increasing index sequence . Given two sequences and , when another sequence is a subsequence of both and , we call a common subsequence of and . For example, if and , the sequence T'' is a common subsequence of $X$ and $Y$, and the sequence GACT'' is also a common subsequence of and . Note that for any given sequences and , the empty sequence is always their common subsequence.
The All Common Subsequences problem asks you, given two sequences and , to find all distinct common subsequences of and .
Input Format
The first line contains two positive integers and , the lengths of the two input sequences and .
The next two lines give the input sequences and , where each element of a sequence is an English letter, uppercase or lowercase.
The last line contains a non-negative integer .
If , you must output all distinct common subsequences of and , and also how many distinct common subsequences and have.
If , you must output only how many distinct common subsequences and have.
Output Format
Output all distinct common subsequences of and , or output how many distinct common subsequences and have. When , first output all distinct common subsequences of and , one per line, in ascending lexicographic order. Finally, output the number of distinct common subsequences. When , output only the number of distinct common subsequences.
6 6
GCTACT
GATCCT 1
A
AC
ACT
AT
C
CC
CCT
CT
G
GA
GAC
GACT
GAT
GC
GCC
GCCT
GCT
GT
GTC
GTCT
GTT
T
TC
TCT
TT
26
Hint
.
The answer can be very large.
Translated by ChatGPT 5
京公网安备 11011102002149号