设f[i][j][0/1]为前i位选j段时其中第i位选/不选最多能匹配到哪,转移时f[i][j][0]→f[i+1][j][0],f[i][j][1]→f[i+1][j][0],f[i][j][1]→f[i+1][j][1],f[i][j][0]→f[i+1][j+1][1]。失配时找到最后一位相同字符,具体见代码。感觉非常假,欢迎hack。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 100010
#define M 102
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<''||c>'')) c=getchar();return c;}
int gcd(int n,int m){return m==?n:gcd(m,n%m);}
int read()
{
int x=,f=;char c=getchar();
while (c<''||c>'') {if (c=='-') f=-;c=getchar();}
while (c>=''&&c<='') x=(x<<)+(x<<)+(c^),c=getchar();
return x*f;
}
int T,n,m,t,f[N][M][],pre[N][];
char a[N],b[N];
int main()
{
#ifndef ONLINE_JUDGE
freopen("bzoj5073.in","r",stdin);
freopen("bzoj5073.out","w",stdout);
const char LL[]="%I64d\n";
#else
const char LL[]="%lld\n";
#endif
T=read();
while (T--)
{
n=read(),m=read(),t=read();
scanf("%s",a+),scanf("%s",b+);
for (int i=;i<;i++) pre[][i]=-;
for (int i=;i<=m;i++)
{
for (int j=;j<;j++)
pre[i][j]=pre[i-][j];
pre[i][b[i]-'a']=i;
}
f[][][]=-;
bool flag=;
for (int i=;i<=n;i++)
{
f[i][][]=-;
for (int j=;j<=t;j++)
{
f[i][j][]=max(f[i-][j][],f[i-][j][]);
f[i][j][]=pre[max(f[i-][j-][],f[i-][j][])+][a[i]-'a'];
if (f[i][j][]==m) {flag=;break;}
}
if (flag) break;
}
if (flag) puts("YES");else puts("NO");
}
return ;
}