Background
You're here, there's nothing I fear,
And I know that my heart will go on.
We'll stay forever this way.
You are safe in my heart.
And my heart will go on and on.
Description
The male wants to express his love for the female in three sentences. Male is mainly engaged in tempering these three sentences. Now, what needs to be done to find the everlasting things in the three sentences, the longest common subsequence length and number of common subsequences of the three sequences are calculated. The number of them is the modulo of the 201,314th prime numbers (2769433. Matching between characters is case insensitive (that is, "a" and "A" are considered equal)
Input Format
There are three rows in total, one row and one letter sequence.
Output Format
The longest common sub-sequence length of the first line.
In the second row, the number of public subsequences of the three sequences is the answer to the modulo operation of 201,314th prime numbers (2769433.
Sample Input
INeedYou
IMissYou
ILoveYou
Sample output
4
15
Data scope and conventions
For 100% of the data, the sequence only contains uppercase and lowercase letters, and the sequence length is both.
Example
The longest common subsequence is IYou and the length is 4. The common subsequence is I Y o u IY Io Iu Yo Yu ou IYo IYu Iou You IYou, 4 + 6 + 4 + 1 = 15
Source
This question has a non-exercise version ......
This is to count the number of common subsequences + deduplication
The Forward Solution uses the Exclusion Principle and allows empty strings.
F [I] [J] [K] = 2F [I-1] [J-1] [K-1]-F [I '-1] [J'-1] [K'-1] I ', j', K' is the position where I, J, and K appear before a [I], B [J], and c [k] (if not, do not subtract it)
Assume that deduplication has been performed before, F [I] [J] [K] only needs to be deduplicated with F [I '-1] [J'-1] [K'-1.
[Cpp] # include <cstdio>
# Include <cstring>
# Include <cstdlib>
# Include <cmath>
# Include <functional>
# Include <algorithm>
# Include <cctype>
Using namespace std;
# Define F (2769433)
# Define MAXN (100 + 10)
# Define For (I, n) for (int I = 1; I <= n; I ++)
# Define Rep (I, n) for (int I = 0; I <= n; I ++)
Int len1, len2, len3, f [MAXN] [MAXN] [MAXN], pre1 [MAXN], pre2 [MAXN], pre3 [MAXN], s [500];
Char a [MAXN], B [MAXN], c [MAXN];
Void make_pre (char * a, int n, int * pre)
{
Memset (s, 128, sizeof (s ));
Memset (pre, 0, sizeof (pre ));
For (I, n)
{
A [I] = tolower (a [I]);
Pre [I] = s [a [I];
S [a [I] = I;
}
}
Int main ()
{
Memset (f, 0, sizeof (f ));
Scanf ("% s", a + 1, B + 1, c + 1 ); a [0] = B [0] = c [0] = '';
Len1 = strlen (a)-1, len2 = strlen (B)-1, len3 = strlen (c)-1;
Make_pre (a, len1, pre1 );
Make_pre (B, len2, pre2 );
Make_pre (c, len3, pre3 );
Int cnt = 0;
For (I, len1)
For (j, len2)
For (k, len3)
If (a [I] = B [j] & B [j] = c [k]) f [I] [j] [k] = f [I-1] [J-1] [k-1] + 1;
Else f [I] [j] [k] = max (f [I-1] [j] [k], f [I] [J-1] [k]), f [I] [j] [k-1]);
Cnt = f [len1] [len2] [len3];
// Memset (f, 0, sizeof (f ));
Rep (I, len1) Rep (j, len2) Rep (k, len3) f [I] [j] [k] = 1;
For (I, len1)
For (j, len2)
For (k, len3)
{
F [I] [j] [k] = 0;
If (a [I] = B [j] & B [j] = c [k])
{
F [I] [j] [k] = (10 * F + f [I-1] [J-1] [k-1] * 2) % F;
If (pre1 [I]> 0 & pre2 [j]> 0 & pre3 [k]> 0) f [I] [j] [k] = (F + f [I] [j] [k]-f [pre1 [I]-1] [pre2 [j]- 1] [pre3 [k]-1]) % F;
// If (! Pre1 [I] |! Pre2 [j] |! Pre3 [k]) f [I] [j] [k] --;
}
Else
{
F [I] [j] [k] = (10 * F + f [I-1] [j] [k] + f [I] [J-1] [k] + f [i] [j] [k-1]-f [I-1] [J-1] [k]-f [I] [J-1] [k-1]-f [I-1] [j] [k-1] + f [I-1] [J-1] [k-1]) % F;
}
}
Printf ("% d \ n", cnt, (F + f [len1] [len2] [len3]-1) % F );
Return 0;
}