Solution for problem 18

dynamic programming, woohoo!