Analysis
- First of all the name "string dp" is my take ...... Anyway chaos out on the string thing
- The second to do, knowing that this is the case dp, still are not determined. . After roughly glanced definition, still no transfer of right. Ten first dish is Sin
Consider two strings
are generally required to record in the state, respectively, in which the current position of each string is
then the first two dimensions we define out
expressed in A bit string before i, B j-bit string before
Etc., such a definition is very clear
Hou dp God said state definition must be as clear as possible
what is carried out?
For a
match to the j-th bit string B
Consider the information in the title, we need to extract a record number string
plus one-dimensional [k] denotes a k-string extracted
Finally, consider the transfer
due to continuous string, so when we have to know that the transfer of a position on the election no
oh, plus a one-dimensional [0/1] (anyway, as long as you need Gaga Gaga)
In summary, we define a long way out of the state:
Transfer le?
in case
this position is not selected.
if
this position to choose, be sure to satisfy
Haha, Wanla
And so, like open space no less? ? (Should be able to live)
rolling out of, oh friends
(if you want to scroll, remember to look at the anti-enumeration order. Because the information prior to call)
There is also a 0/1 remember no state is defined
in fact essentially the same as this one is to see the current
given
is equal to the time, whether alone into a string
Code
#include<bits/stdc++.h>
using namespace std;
inline char nc(){
static char buf[100000],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define nc getchar
inline int read(){
int x=0,f=1;
char ch=nc();
while(!isdigit(ch)&&ch!='-')ch=nc();
if(ch=='-')ch=nc(),f=-1;
while(isdigit(ch)){x=(x<<1)+(x<<3)+ch-48;ch=nc();}
return x*f;
}
const int N=1002,M=202;
typedef long long ll;
const int mod=1e9+7;
ll dp[M][M][2];
int n,m,k;
char a[N],b[M];
int main(){
n=read();m=read();k=read();
scanf("%s",a+1);
scanf("%s",b+1);
dp[0][0][0]=1;
for(int i=1;i<=n;i++)
for(int j=m;j>=1;j--){
if(a[i]!=b[j]){
for(int l=0;l<=k;l++){
dp[j][l][0]=(dp[j][l][0]+dp[j][l][1])%mod;
dp[j][l][1]=0;
}
}
else{
dp[j][0][0]=(dp[j][0][0]+dp[j][0][1])%mod;
for(int l=k;l>=1;l--){
dp[j][l][0]=(dp[j][l][0]+dp[j][l][1])%mod;
dp[j][l][1]=(dp[j-1][l-1][0]+dp[j-1][l-1][1]+dp[j-1][l][1])%mod;
}
}
}
printf("%lld",(dp[m][k][0]+dp[m][k][1])%mod);
return 0;
}