using dynamic programming to solve scramble string problem