Dynamic programming algorithms implementations