I was trying to solve this problem on spoj that involves LCS with some other constraints. I have come with a recursive solution which gives correct answer on all cases. But when I try to memoziate it, it gives wrong answer. I am not able to figure out why it gives wrong answer on memoziation. my code is here with explanation.
With your recursive approach, you will need N*N*K memory to store everything which is a lot, the WA might be a RE due to not having enough space to allocate your arrays.