python recursion instead of dp