Implementing dynamic programming prolems