看看我的解法。
// suppose all the beginning of all the records are in the increasing order
struct record
{
double begin;
double end;
double weight;
};
double getMaxWeight(double begin, double end, record* a, int number)
{
if (number == 1)
return (a[0].begin >= begin && a[0].end <= end)?a[0].weight:0;
else if (a[1].begin >= a[0].end)
return a[0].weight+getMaxWeight(a[1].begin, end, a+1, number-1);
else
return max(a[0].weight+getMaxWeight(a[0].end, end, a+2, number-2),
getMaxWeight(a[1].begin, end, a+1, number-1));
}