Implemented memory-based dynamic programming aproach