Frog 2 at codeer dp

for(ll j=1; j<=k; j++) {
if(i-j>=0) {
dp[i] = min(dp[i], dp[i-j] + llabs(h[i-j]-h[i]));
}

In this dp provlem I camnnot uder stand significance of this line
dp[i-j] + llabs(h[i-j]-h[i]));

hello @Somasree

here we r at i and we have take j jump.
that means its previous location will be i-j.

dp[i]=cost to reach i-j + cost of jump from i-j to i.
dp[i]=dp[i-]+abs(h[i-j]-h[i]));

ok understood.thank u

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.