Problem Description
LYD loves codeforces since there are many Russian contests. In an contest lasting for T minutes there are n problems, and for theith 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 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
题意:LYD要打CF,一共n道题,t单位时间,每道题都有初始分数a,每单位时间减的分数d和做出这道题需要多长时间c,求最大的得分;
思路:这题不是跟以前的背包一样,这题后面选的每个东西都跟前面有关的。。前面的那种背包无关顺序,所以这种肯定要排个序,如果是无序的,这个最优过程中选的也不一定按照最优顺序的。。只是这种顺序的最优解,比如 11 1 1 ,11 1 10从前往后分别是11分, 1分钟做完,每秒掉1/10分,这也最优就是10分,第二个都成了0分,如果第一个在前面 就不一样了。。
然后按照怎样的顺序排序呢
假设有两个题, 第一个题 a.c a.d 第二个题 b.c b.d 两种顺序减得分分别是 a.c*a.d+(b.c+a.c)*b.d 〈 b.c*b.d+(b.c+a.c)*a.d 化简就是a.c/a.d < b.c/b.d
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,t;
struct node
{
int t,d,c;
double f;
}ff[2005];
bool cmp(node a,node b)
{
return a.f<b.f;
}
int dp[5000];
int main()
{
while(cin>>n>>t)
{memset(dp,0,sizeof(dp));
for(int i=1;i<=n;++i)
{
scanf("%d",&ff[i].t);
}
for(int i=1;i<=n;++i)
{
scanf("%d",&ff[i].d);
}
for(int i=1;i<=n;++i)
{
scanf("%d",&ff[i].c);ff[i].f=ff[i].c*1.0/ff[i].d;
}
sort(ff+1,ff+n+1,cmp);
int maxn=0;
for(int i=1;i<=n;++i)
{
for(int v=t;v>=ff[i].c;--v)
{
dp[v]=max(dp[v],dp[v-ff[i].c]+ff[i].t-ff[i].d*v);
maxn=max(dp[v],maxn);
}
}
cout<<maxn<<endl;
}
return 0;
}