Description
LYD loves codeforces since there are many Russian contests. In an contest lasting forT minutes there aren problems, and for the ith problem you can getai−di∗ti points, whereai indicates the initial points,di indicates the points decreased per minute (count from the beginning of the contest), andti stands for the passed minutes when you solved the problem (count from the begining 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 as he can?
Input
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
Output an integer in a single line, indicating the maximum points LYD can get.
Example Input
3 10
100 200 250
5 6 7
2 4 10
Example Output
254
Hint
Author
题意
一个比赛中有n个题,限制时间为T,现在已知你做第i题需要时间为di,得到的分数为ai-di*ti,其中ti为完成这道题的时间
每次只能同时做一道题,求比赛能得到的最大分数。
题解
算是比较简单的01背包吧,反正就是看完题就能有大体思路吧。
不过要注意的是,这个题是跟次序有关的,要对ai,di,ci进行排序。刚开始没注意这点,用三个数组做的,然后wa了好久...
题目抽象:容量T,个数为n,每个占的容量为di,价值跟时间有关,为ai-di*t。
可以放在结构体里,跟J题差不多排序,注意要按照di/ci倒序排序,因为di越大、ci越小,消耗的分数越大,应该尽量往前放
可以称di为增长系数吧,根据背包最优策略求一下就好了
代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
/*
* @author Smilewei
*/
struct contest
{
int a,d,c;
}con[5010];
bool cmp(contest x,contest y)
{
return (1.0*x.d/x.c)>(1.0*y.d/y.c);
}
int main()
{
int n,T;
scanf("%d%d",&n,&T);
for(int i=0;i<n;i++)
{
scanf("%d",&con[i].a);
}
for(int i=0;i<n;i++)
{
scanf("%d",&con[i].d);
}
for(int i=0;i<n;i++)
{
scanf("%d",&con[i].c);
}
int dp[5010];
for(int i=0;i<T;i++)
{
dp[i]=0;
}
sort(con,con+n,cmp);
int maxn=0;
for(int i=0;i<n;i++)
{
for(int t=T;t>=con[i].c;t--)
{
dp[t]=max(dp[t],dp[t-con[i].c]+max(con[i].a-con[i].d*t,0));
if(maxn<dp[t])maxn=dp[t];
}
}
cout<<maxn<<endl;
return 0;
}