Dynamic programming algorithm case realization