您的位置:首页 > 其它

codeforces(背包)

2017-08-15 20:17 507 查看


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.

样例输入1 复制
3 10
100 200 250
5 6 7
2 4 10


样例输出1
254
思路:对于每个题,都会随时降分,设两个题 a,b , 则对于da  db  ta  tb ,如果能做,都能做完,该先做那个哪? 我是这样判断的:如果先做a那么总的浪费就是(at + bt) * db   +  at * da     若先做 b题那么总的浪费将是 (at+bt)*da + bt * db      令1式<2式,得到 at/da  < bt/db  
那么就得到了优先级,即
t/d小的优先,排完序后,按照0,1背包的思路判断每个题做还是不做,得到答案。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct node{
int score;
int d;
int t;
double op;
bool operator <(const node nd)const
{
return op < nd.op;
}
};
node a[100005];
int cash[50000];
int dp[100050];
int main()
{
int n,T;
scanf("%d%d",&n,&T);
for(int i = 1; i <= n; i++)
scanf("%d",&a[i].score);
for(int i = 1; i <= n; i++)
scanf("%d",&a[i].d);
for(int i = 1; i <= n; i++)
{
scanf("%d",&a[i].t);
a[i].op = a[i].t*1.0 / a[i].d;
}
sort(a+1,a+1+n);
int max_ = -1;
for(int i = 1; i <= n; i++)
{
for(int j = T; j >= a[i].t; j--)
{
dp[j] = max(dp[j],dp[j-a[i].t] + max(0,a[i].score - j*a[i].d));
max_ = max(max_,dp[j]);
}
}
printf("%d\n",max_);
return 0;
}


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: