codeforces
发布时间: 2017年5月13日 22:40 最后更新: 2017年5月14日 16:39 时间限制: 1000ms 内存限制: 128M
LYD loves codeforces since there are many Russian contests. In an contest lasting for T minutes there are n problems, and for the ith problem you can get ai−di∗ti points, where ai indicates the initial points, di indicates the points decreased per minute (count from the beginning of the contest), and ti stands for the passed minutes when you solved the problem (count from the beginning of the contest).
Now you know LYD can solve the ith problem in ci minutes. He can't perform as a multi-core processor, so he can think of only one problem at a moment. Can you help him get as many points ashe can?
The first line contains two integers n,T(0≤n≤2000,0≤T≤5000).
The second line contains n integers a1,a2,..,an(0<ai≤6000).
The third line contains n integers d1,d2,..,dn(0<di≤50).
The forth line contains n integers c1,c2,..,cn(0<ci≤400).
Output an integer in a single line, indicating the maximum points LYD can get.
3 10 100 200 250 5 6 7 2 4 10
254
第一次接触贪心加背包的题(巨弱。。。。。。一直写裸的01背包,还想不出来错,以为背包都可以跑出来。。。。。。。浪费了很长时间
举一个很简单的例子两个题目 AB,给定时间内都可以解决(T>=c1+c2),先解决A后解决B可以得到的分数是(a1-c1*d1+a2-(c1+c2)*d2),而先解决B后解决A可以得到的分数是(a1-(c1+c2)*d1+a2-c2*d2),两者不同的地方是 -c1*d2 -c2*d1 ,所以应该是d越大的越靠前,c越小的越靠前,这样首先根据d/c 的值排序,再背包
#include<bits/stdc++.h>
using namespace std;
struct node
{
int a,d,c;
}num[2005];
int dp[5005];
int cmp(node u,node v)
{
return u.c*v.d<v.c*u.d;
}
int main()
{
int T,n,i,j;
cin>>n>>T;
for(i=0;i<n;i++)
scanf("%d",&num[i].a);
for(i=0;i<n;i++)
scanf("%d",&num[i].d);
for(i=0;i<n;i++)
scanf("%d",&num[i].c);
sort(num,num+n,cmp);
int ans=0;
for(i=0;i<n;i++)
{
for(j=T;j>=num[i].c;j--)
{
dp[j]=max(dp[j],dp[j-num[i].c]+max(num[i].a-num[i].d*j,0));
ans=max(ans,dp[j]);
}
}
cout<<ans<<endl;
return 0;
}