LCS print question

can any one suggest me recursive dp solution for
LCS print problem


my this code is code is not working proper

@ankit_verma
Will get back to you asap

@ankit_verma
dp[i][j]=a[i]+dp[i-1][j-1];

    return solve(a,b,i+1,j+1,dp);

In this line, you have assumed that dp[i-1][j-1] has already been computed. But that is not at all necessary in case of top down dp. Please try to correct this. Please revert in case you face any difficulty.

@LP18Aug0068

this code is also not accepting why??

@ankit_verma
This problem is arising because you have passed v by reference. Because of which, because many states are being computed, many characters are being inserted in v because of which the answer is turning out be wrong. You should compute the dp matrix using recursion and compute the output string using recursion. This is a better approach. Also take a bigger dp matrix because the constraints are bigger.

Please revert in case you face any difficulty.

i am not understanding clearly
and i have tried to bug fix but
iā€™m not able to optimise it so help in
it

@ankit_verma
What I am trying to say is that you should construct the dp array using recursion. You can also do it using 2 nested for loops without recursion. To find the lcs, you should start from index (n, m) and go on till (0, 0). This is basis for this question. Please revert in case you face any difficulty.

i want to do only using recursion method i already studied the nested loop method

@ankit_verma
For the recursion portion, you are calculating the dp matrix absolutely correctly. Just dont calculate the ouput during the same time. Make a different function call after you have performed the calculations for the dp matrix.

Please revert in case you face any difficulty.

now i am not get anything please send me the recursion solution so that i will be cleared
and know this concept

@ankit_verma
Will revert asap

please give that solution!!!

@LP18Aug0068
hello!!!

@LP18Aug0068 can i get my ans or not???

@LP18Aug0068 hello please give me solution for that?