My Dynamic Programming Problem works