dynamic programming algorithm generator