adding a dp approach for kt chapter6 question 9b.