Dynamic programming
There are n colorful tiles arranged in a line T1,T2,...,Tn. Each tile is colored with either Red. Green or Blue color.T is Red.
A frog, which is currently on Ti, is trying to reach Tn However, the jumps of the frog are restricted as follows:
l. If it is currently on tile i, then it can only jump to a tile j where j > i.
2. The sequence of the color of the tiles on which it jumps must be in the following specific order: Red Green, Blue, Red, Green, Blue, ....
The jumps can be arbitrarily long. However, longer jumps are harder: a jump of length k costs k * k energy
Note that the final tile Tn also has some color and thus the frog must reach it in a corresponding step. Given an input E {Red,Green,Blue}n, i.e., the sequence of the colors of the tiles, design an algorithm that returns the smallest possible total cost of doing so. If it is impossible to reach the final tile, return -1.