计算机问题求解一论题3-2 贪心算法 2016年09月07日
计算机问题求解 – 论题3-2 - 贪心算法 2016年09月07日
问题1: 你还记得什么是“Optimal Substructure吗?该结构特 性对求解最优解问题有什么肩 发?
Activity Selection Problem Suppose we have a set S=fa,a2....n of n proposed acivities that wish to use a resoure,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 time fi,where 0si<fi<oo.If selected,activity ai takes place during the half-open time interval [si,).Activities a and a are compatible if the intervals [si,)and [s,)do not overlap.That is,ai and aj are compatible if s ors In the activity-selection problem,we wish to select a maximum-size subset of mutually compatible activities. 一个样本输入 5678 10 8 8 2 12 99 11 14
Activity Selection Problem 一个样本输入:
问题2: Activity Selection问题是否具 有“最优子结构”,为什么?
S表示开始时间不早于活动a的结束时间,而 结束时间早于α的结束时间的所有活动的集合。 If we denote the size of an optimal solution for the set S by ci,],then we would have the recurrence cli,j]=cli,k]+ck,j+1. 假设我们知道其中包含活动a。 S中最多相互兼容的活动数 0 if Sij=0 ci,小= max {cli,k]+ck,j]+1 if Si ak∈SiU
Sij表示开始时间不早于活动ai的结束时间,而 结束时间早于aj的结束时间的所有活动的集合。 Sij中最多相互兼容的活动数 假设我们知道其中包含活动ak