2017第八届浪潮杯山东省赛 K题 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
254
题意:cf上做题,总共有n个题目,每个题目有对应的a,d,c 其中c是解决这个问题需要的时间,a和d决定解决这个题目能得到的分数,在t时刻解决这个题目可以得到a-t*d的分数,问在T时间内最多能得多少分


第一次接触贪心加背包的题(巨弱。。。。。。一直写裸的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;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值