codeforces(背包)

codeforces

发布时间: 2017年5月13日 22:40   最后更新: 2017年5月14日 16:39   时间限制: 1000ms   内存限制: 128M

Clipboard Image.png

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
思路:对于每个题,都会随时降分,设两个题 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;
}



  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值