![](https://img-blog.csdn.net/20170412231221235?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvR1FfQk9C/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
#include<iostream>
#include<algorithm>
using namespace std;
struct bg {
int hap; //欢乐度
int last; // 持续时间
int time; //必须离开时间
};
bg b[40];
bool comp(const bg &a, const bg &b) { //先必须离开的在前
return a.time < b.time;
}
int main()
{
int n;
while (cin >> n && n>0) {
int dp[1000] = {0};
for (int i=0; i!=n; ++i)
cin >> b[i].hap >> b[i].last >> b[i].time;
sort (b, b+n, comp);
for (int i=0; i!=n; ++i) //类似01背包选择
for (int j=b[i].time; j>=b[i].last; --j)
if (dp[j] < dp[ j-b[i].last ] + b[i].hap)
dp[j] = dp[j-b[i].last] + b[i].hap;
int ans = 0;
for (int i=0; i<=b[n-1].time; ++i)
ans = max(ans, dp[i]);
cout << ans << endl;
}//while
return 0;
}
/**************************************************************
Problem: 1030
User: cust123
Language: C++
Result: Accepted
Time:0 ms
Memory:1520 kb
****************************************************************/
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstring>
#include <stack>
#include <string>
#include <string.h>
#include <stdio.h>
#include <cmath>
#include <map>
#include <functional>
#include <set>
#include <limits.h>
#include <math.h>
#include <ctype.h>
using namespace std;
//1030
struct node{
int a,b,c;
}node[31];
bool mark[31];
int n,h,l,t,high,sum,mx,ans;
void dfs(int high,int sum)
{
if(high>ans) ans=high;
for(int i=1;i<=n;i++)
{
if(mark[i]==false && sum+node[i].b<=node[i].c)
{
mark[i]=true;
dfs(high+node[i].a,sum+node[i].b);
mark[i]=false;
}
}
}
int main()
{
//freopen("input.txt","r",stdin);
while(scanf("%d",&n)!=EOF && n>=0)
{
memset(mark,0,sizeof(mark));
for(int i=1;i<=n;i++)
scanf("%d %d %d",&node[i].a,&node[i].b,&node[i].c);
ans=0;
dfs(0,0);
printf("%d\n",ans);
}
return 0;
}
/**************************************************************
Problem: 1030
User: cust123
Language: C++
Result: Accepted
Time:10 ms
Memory:1520 kb
****************************************************************/