codility 青蛙跳石头

https://stackoverflow.com/questions/39881068/frog-jumps-across-a-river-with-stones
Note that the earliest time you can reach
x = ican be expressed by the following recurrence relation:shortest[i] = if A[i] = -1 then +inf else max(A[i], min{shortest[j] | i - D <= j < i})So first there is a simple
O(ND)solution using only dynamic programming.This can actually be reduced to
O(N + D)using an efficient algorithm to maintain the mininum ofshorteston the sliding window[i-D ... i](using double-ended queue).

浙公网安备 33010602011771号