Description
An adorable, but lazy, quokka is descending through the branches of a tree, eating leaves on it’s way
home to sleep. The tree is represented by a matrix w wide and h high. Each position is an integer,
representing how tasty the leaves are. These integers can be negative, because some of the leaves have
bugs on.
Start point:
The quokka always starts in the top right corner of the tree (i.e. position (w, h)). This corner of the tree
will always have a value of 0.
End point:
The quokka wants to go home to it’s nest at the bottom left corner of the tree (i.e. position (1, 1)).
Jumping down:
The quokka can jump directly down to a new row. It can skip zero or more rows when it does this, but
it will always eats the leaf it lands upon.
Hopping left:
The quokka can hop to the left, one step at a time, eating every leaf it finds, even if it is not tasty (it’s
hungry!) Because it is a lazy quokka and has tiny legs, it quickly gets tired – each consecutive step to
the left incurs a score penalty:
• The first step left costs 1 point
• The second consecutive left costs 2 points
• The third consecutive left costs 3 points
• etc.
Happily, it enjoys jumping so much that whenever it moves down to a new branch it forgets how tired
it’s little feet were getting. Therefore the next time it decides to move left, the penalty cost will be back
down to just 1 point again.
Other directions
The quokka never moves right or upwards, because it is sleepy and wants to get home quickly.
Objective
Use dynamic programming to calculate the maximum happiness that the quokka can achieve at the end
of it’s journey from the top right to the bottom left. The quokka’s happiness is defined by the sum of
the leaves it ate, minus the penalties accumulated from hopping left along the branche