DP问题
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAX = 30;
struct node{
int h, t, en;
}po[MAX];
int dp[10000];
bool cmp(const node &a,const node &b)//比较函数,为sort()函数提供风向标
{
return a.en < b.en;
}
int main()
{
int n;
while(scanf("%d", &n) && n > 0)
{
for(int i = 0;i < n; ++ i)
scanf("%d%d%d", &po[i].h, &po[i].t, &po[i].en);
sort(po, po + n, cmp);
memset(dp, 0, sizeof(dp));
int maxx = 0;
for(int i = 0;i < n; ++ i)
{
int w = po[i].h, v = po[i].t;
for(int k = po[i].en;k >= po[i].t; -- k)
{
dp[k] = max(dp[k], dp[k - v] + w);
maxx = max(dp[k], maxx);
}
}
printf("%d\n", maxx);
}
}