結果 : write the algorithm for dynamic programming