Jam City Interview Question

Basic recursion and dynamic programming.