题目链接
按贪心的策略就是每分钟减少的价值大的应该尽可能的先拿走
不妨先排序,然后按T去01背包取不取。
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int N,T;
const int maxn=55;
const int maxt=1e5+5;
ll dp[maxt];
struct node
{
int ma;//最大分数
int pm;//每分钟减小的分数
int re;//需要的时间
bool operator <(const node& rhs) const{
return pm*1.0/re > rhs.pm*1.0/rhs.re;
}
}nc[maxn];
int main()
{
cin>>N>>T;
for(int i=0;i<N;i++) cin>>nc[i].ma;
for(int i=0;i<N;i++) cin>>nc[i].pm;
for(int i=0;i<N;i++) cin>>nc[i].re;
sort(nc,nc+N);
ll ans=0;
for(int i=0;i<N;i++){
for(int j=T;j>=nc[i].re;j--){
dp[j]=max(dp[j],dp[j-nc[i].re]+nc[i].ma-nc[i].pm*j);
ans=max(dp[j],ans);
}
}
cout<<ans<<endl;
}