计算机问题求解一论题3-2 。贪心算法 2018年09月18日
计算机问题求解 – 论题3-2 - 贪心算法 2018年09月18日
间题1: 你还记得什么是“Optimal Substructure”吗?该结构特 性对求解最优解间题有什么启 发?
Activity Selection Problem Suppose we have a set S=fa,a2.... of n proposed activities that wish to use a resource,such as a lecture hall,which can serve only one activity at a time.Each activity a has a start time s and a finish timefi,wheres<f<o.If selected,activity ai takes place during the half-open time interval [)Activitiesa and a are compatible if the intervals [s)and [sj,)do not overlap.That is,a;and aj are compatible if si or sj In the activity-selection problem,we wish to select a maximum-size subset of mutually compatible activities. 一个样本输入: 5678 10 8 8 2 11 14 6
Activity Selection Problem 一个样本输入:
问题2: Activity Selection问题是否具 有“最优子结构”,为什么?
S表示开始时间不早于活动a的结束时间,而 结束时间早于α的结束时间的所有活动的集合。 If we denote the size of an optimal solution for the set S by ci,j],then we would have the recurrence ci,j川=ci,k]+c[k,j川+1 假设我们知道其中包含活动ak。 S,中最多相互兼容的活动数 0 c,小=} if Sij=0 max{c[i,k]+c[k,门+l}ifS≠0 kESij
Sij表示开始时间不早于活动ai的结束时间,而 结束时间早于aj的结束时间的所有活动的集合。 Sij中最多相互兼容的活动数 假设我们知道其中包含活动ak