思路:
奶牛吃垃圾,离谱
dp
设f[i]表示当高度为h时,奶牛能存活的最长时间
有点像01背包
C o d e Code Code:
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
struct node
{
int t, f, h;
}a[1100];
bool cmp(node a,node b){return a.t < b.t;} //排序
int dep, n;
int f[1100];
int main()
{
freopen ("rubbish.in","r",stdin);
freopen ("rubbish.out","w",stdout);
scanf ("%d%d", &dep, &n);
for(int i = 1; i <= n; i++)
scanf("%d%d%d",&a[i].t, &a[i].f, &a[i].h);
sort(a + 1, a + n + 1, cmp);
f[0] = 10;
for(int i = 1; i <= n; i++)
for(int j = dep; j >= 0;j--)
if(f[j] >= a[i].t) //dp
{
if(a[i].h + j >= dep)
{
printf("%d\n",a[i].t);
return 0;
}
else
{
f[j + a[i].h] = max(f[j + a[i].h], f[j]);
f[j] += a[i].f;
}
}
printf("%d",f[0]);
return 0;
}