dynamic programming and graphs'