I tried to implement the bottom-up approach of the given problem but it isn’t working correctly, please help me out and tell me what’s wrong with my code.
Code: https://ide.codingblocks.com/s/244239
Please Healp in Bottom Up Approach of given problem
@hargovind
it is mostly like LCS just a dimension k is added
First as a base case calculate dp[i][j][x] where x=0.(same to LCS).
then for x=1 to k.The recurrence relation will be like this:-
long long m1 = max(dp[i-1][j][k], dp[i][j-1][k]);
if (v[i-1]==w[j-1])
dp[i][j][k]=max(m1,dp[i-1][j-1][k]+1);
else
dp[i][j][k]=max(m1, dp[i-1][j-1][k-1]+1);
}
@sanyamsinghalmnnit I have made the changes you told, but I’m getting a random output, please e look at the code. https://ide.codingblocks.com/s/244802
@hargovind
initialize your multidimensional with zero using memset.
For furthur doubts you can also have a look at this code https://ide.codingblocks.com/s/244824
1 Like