标签:
3 6 3 3 3 2 2 4 1 3 4 5 1 1 10 2 3 6 1 2 3 1 1 -1
7 16
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#pragma comment(linker, "/STACK:102400000,102400000")
struct s
{
int w,l,t;
}b[50];
int cmp(const void *a,const void *b)
{
return (*(struct s *)a).t-(*(struct s *)b).t;
}
int n,ans;
void dfs(int i,int sum,int time)
{
if(i==n)
{
if(sum>ans)
ans=sum;
return;
}
if(time+b[i].l<=b[i].t)
dfs(i+1,sum+b[i].w,time+b[i].l);
dfs(i+1,sum,time);
}
int main()
{
//int n;
while(scanf("%d",&n)!=EOF,n>=0)
{
int i;
for(i=0;i<n;i++)
{
scanf("%d%d%d",&b[i].w,&b[i].l,&b[i].t);
}
qsort(b,n,sizeof(b[0]),cmp);
ans=0;
dfs(0,0,0);
printf("%d\n",ans);
}
}标签:
原文地址:http://blog.csdn.net/yu_ch_sh/article/details/44680453