K ordered lcs :

may you please tell me the approach how to do it using 3d dp as I am unable to understand the working of code on geeks for geeks , algorithm and one sample dry run will help me a lot

if(a[n]==b[m])
res=1+LCS(a,b,n+1,m+1,k);
else
{
if(k>0)
{
res=1+LCS(a,b,n+1,m+1,k-1);
}
res=max(res,LCS(a,b,n,m+1,k));
res=max(res,LCS(a,b,n+1,m,k));
}

This is the basic approach you need to follow…as if the value of both strings are equal, then you will calculate normally without changing k , but if values are different , then u will decrement the value of k and will follow the normal approach you use for lcs …