Tried using dynamic programming to solve it. I think there's a subtle bug in dynamic.py that's make it take forever to run and run incorrectly