Problem
A super frog starts on platform 1 of N platforms. It can jump 1, 2, or 3 platforms forward. The cost is the absolute height difference.
Some platforms are broken (height = ā1) ā the frog cannot land on them!
Find the minimum total cost to reach platform N.
Some platforms are broken (height = ā1) ā the frog cannot land on them!
Find the minimum total cost to reach platform N.
š§ DP Concept
This extends Frog Jump with two new challenges:
1. Three jump options instead of two: check dp[iā1], dp[iā2], AND dp[iā3].
2. Broken platforms: if height[i] = ā1, skip that platform (don't update dp[i]).
Also check that the source platform isn't broken and that iāj ā„ 1 before reading dp[iāj].
Recurrence: dp[i] = min over jā{1,2,3} of (dp[iāj] + |h[i]āh[iāj]|), skipping broken sources.
1. Three jump options instead of two: check dp[iā1], dp[iā2], AND dp[iā3].
2. Broken platforms: if height[i] = ā1, skip that platform (don't update dp[i]).
Also check that the source platform isn't broken and that iāj ā„ 1 before reading dp[iāj].
Recurrence: dp[i] = min over jā{1,2,3} of (dp[iāj] + |h[i]āh[iāj]|), skipping broken sources.
Input Variables (pre-loaded)
š” Height ā1 means broken (š). Use if height ā ā1 to skip broken platforms.
Your Output
Result
ā
Run your program to see the result.
Execution Log
Ready. Press ā¶ Run to start.
Expected Answer
Answer:
?
Hint
Step 0