Editorial for COCI '07 Contest 5 #5 Barica
Submitting an official solution before solving the problem yourself is a bannable offence.
The core of the solution is a dynamic programming algorithm. To start with, sort the points in ascending order of x-coordinates, breaking ties in ascending order of y-coordinates.
Let be the largest amount of energy Barica can have after getting from plant to plant .
Barica can reach plant jumping to the right or upwards. As the length of the jump is insignificant, of all plants with the same x-coordinate (and smaller y-coordinate) as plant , we want the one we can reach with the largest amount of energy, that is for which is largest. We apply the same reasoning to plants with the same y-coordinate.
Finally, is calculated as the better of two cases (jumping upwards from the best plant with the same x-coordinate, or jumping to the right from the best plant with the same y-coordinate).
To reconstruct the frog's route, remember for each plant the best plant to have come from.
Comments