application of dynamic programming for algorithms