Dynamic Programming And Recursion In Python