Transmission Door
The very obvious DP
Set f [i] [j] [K] [1/0] indicates that the current consideration of a string I-bit, matched to the B-string J-bit, has been divided into K, is currently selected or not selected
If a [i]≠b [j] then the current bit is not selectable, then only one transfer f [i] [j] [K] [0] = f [I-1] [j] [K] [0] + f [i-1] [j] [K] [1 ]
If a [i] = B [j] then consider selecting the current bit, one more transfer
f [i] [j] [K] [1] = f [i-1] [j-1] [k-1] [0] + f [i-1] [j-1] [K] [1] + f [i-1] [j-1] [k-1] [ 1]
Note If the previous one also has a selection, then the current bit can be merged with the previous one, separate one
Note that the space is completely insufficient, so to scroll the array optimization off I
#include <iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>using namespaceStd;typedefLong LongLl;inlineintRead () {intx=0, f=1;CharCh=GetChar (); while(ch<'0'|| Ch>'9') {if(ch=='-') f=-1; Ch=GetChar ();} while(ch>='0'&&ch<='9') {x= (x<<1) + (x<<3) + (ch^ -); Ch=GetChar ();} returnx*F;}Const intn=1007, m=207, mo=1e9+7; inlineintfkintx) {returnX>=mo? x-mo:x; }//It's quicker to take more than that .intn,m,t;CharSa[n],sb[m];intf[2][m][m][2];intMain () {n=read (); M=read (); t=read (); scanf ("%s", sa+1); scanf"%s", sb+1); f[0][0][0][0]=1; for(intI=1; i<=n;i++) for(intj=0; j<=m;j++) for(intk=0; k<=t;k++) {F[i&1][j][k][0]=FK (f[(i-1) &1][j][k][0]+f[(I-1) &1][j][k][1] ); if(J&&k&&sa[i]==sb[j])//Note that at this point the j,k cannot be 0f[i&1][j][k][1]=FK (f[(i-1) &1][j-1][k][1]+ FK (f[(i-1) &1][j-1][k-1][0]+f[(I-1) &1][j-1][k-1][1]) ); Elsef[i&1][j][k][1]=0;//because it is a scrolling array, it is important to remember to assign the value to 0 if you cannot select it.} printf ("%d", FK (f[n&1][m][t][0]+f[n&1][m][t][1] )); return 0;}
P2679 Sub-string