1 #include<stdio.h> 2 #include<string.h> 3 #define MAX(x,y)(x>y?x:y) 4 #include<algorithm> 5 using namespace std; 6 struct Node{ 7 int h,l,t; 8 }; 9 int cmp(Node a,Node b){ 10 return a.t<b.t; 11 } 12 Node bg[35]; 13 int N,ans,vis[35]; 14 void dfs(int x,int h,int t){ 15 if(x>=N){ 16 ans=MAX(ans,h); 17 return; 18 } 19 if(t+bg[x].l<=bg[x].t) 20 dfs(x+1,h+bg[x].h,t+bg[x].l); 21 dfs(x+1,h,t); 22 } 23 int main(){ 24 while(scanf("%d",&N),N>=0){ 25 for(int i=0;i<N;i++) 26 scanf("%d%d%d",&bg[i].h,&bg[i].l,&bg[i].t); 27 sort(bg,bg+N,cmp); 28 ans=0; 29 memset(vis,0,sizeof(vis)); 30 dfs(0,0,0); 31 printf("%d\n",ans); 32 } 33 return 0; 34 }
原文:http://www.cnblogs.com/handsomecui/p/4865266.html