我今天才看见 啊
程序代码:#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
int start;
int end;
int price;
}node;
int search(node *a , int i , int num)
{
int j = 0 , max = 0 , total;
for( ; j < num ; j++)
{
total = 0;
if(a[j].start >= a[i].end && j != i)
{
total += a[j].price ;
total += search(a , j , num);
if(total >= max) max = total;
}
}
return max;
}
int main()
{
int num = 0 , total = 0 , max = 0;
printf("请输入数据组数:\n");
scanf("%d" , &num);
node *a = (node *)malloc(sizeof(node) * num);
int i = 0;
printf("请依次输入各组数据:\n");
for( ; i < num ; i++)
scanf("%d%d%d" , &(a[i].start) , &(a[i].end) , &(a[i].price));
for(i = 0 ; i < num ; i++)
{
total = a[i].price;
total += search(a , i , num); //以i为起点开始寻找,每次找开始时间大于其结束时间的;
if(total >= max) max = total ;
}
printf("\n结果为 :%d\n" , max);
free(a);
return 0;
}
