样例过了,36分。谢谢各位大佬。
我这边把饥饿值当作体积,把高度当作价值做背包。
#include<bits/stdc++.h>
using namespace std;
int main()
{
int d,g;
cin>>d>>g;
int t[101],v[101],h[101],dp[100001]={0},V=10;
for(int i=1;i<=g;++i)
{
cin>>t[i]>>v[i]>>h[i];
V+=v[i];
}
for(int i=1;i<=g;++i)
{
int minn=t[i],index=i;
for(int j=i+1;j<=g;++j)
{
if(minn>t[j])minn=t[j],index=j;
}
swap(t[index],t[i]),swap(v[index],v[i]),swap(h[index],h[i]);
}
for(int i=1;i<=g;++i)
{
int x=0;
for(int l=V;l>=v[i]+(t[i]-t[i-1]);--l)
{
dp[l]=max(dp[l-v[i]-(t[i]-t[i-1])]+h[i],dp[l]);
x=max(dp[l],x);
}
if(x>=d)
{
cout<<t[i];
return 0;
}
}
cout<<V;
}