Question
There are two strings A and B... ask how many identical sub-sequences a and B can have...
Question
This is a test of basic skills and thinking abilities .... if string a is a sub-sequence. the question becomes an LCS (change the length to the number of solutions .. same )... this question requires that string a can only be a substring... that is, it can only take consecutive results... so it cannot be transferred like a bare LCs... according to question restrictions .. some transformations are...
Program:
# Include <iostream> # include <stdio. h> # include <string. h> # include <cmath> # include <queue> # include <stack> # include <set> # include <time. h> # include <map> # include <algorithm> # define ll long # define EPS 1e-5 # define oo 1000000007 # define PI ACOs (-1.0) # define maxn 5005 using namespace STD; int DP [maxn] [maxn]; char a [maxn], B [maxn]; int main () {scanf ("% S % s", A + 1, B + 1); int len1 = strlen (a + 1), len2 = strlen (B + 1 ), ans = 0; memset (DP, 0, sizeof (DP); For (INT I = 1; I <= len1; I ++) {for (Int J = 1; j <= len2; j ++) {DP [I] [J] = DP [I] [J-1]; if (a [I] = B [J]) DP [I] [J] + = DP [I-1] [J-1] + 1, DP [I] [J] % = Oo; // DP [I-1] [number of J-1] schemes + only one type of a [I] = B [J ..} ans = (ANS + dp [I] [len2]) % Oo; // The number of solutions is transferred to the end} printf ("% d \ n", ANS );}