【hautoj1307】CF

传送门:点击打开链接
题目描述

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 aiditi 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?

输入

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


题意:
输入n,t,代表n道题 时间为t,第二行a每道题分值,第三行d每分钟失的分,最后一行c完成这道题的用时。求最多得几分。

思路:
先做失分最多的题,先做用时最短的题,结合一下先做失分最多又用时最短的题,即d/c最大的先做,排序。

之后就是01背包,注意dp[n]不一定是最大,因为还要失分。
说一下为什么要排序...如果直接按01做,选的题目不会变,无外乎就是先选后选的问题,问题就出在这,先选后选对于本题来说至关重要....


代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
struct node
{
    int a,c,d;
    double m;
} q[2005];
bool cmp(node x,node y)
{
    if(x.m==y.m)
        return x.c<y.c;
    return x.m>y.m;
}
int dp[5005];
int main()
{
    int i,n,t;
    cin>>n>>t;
    for(i=1; i<=n; i++) scanf("%d",&q[i].a);
    for(i=1; i<=n; i++) scanf("%d",&q[i].d);
    for(i=1; i<=n; i++)
    {
        scanf("%d",&q[i].c);
        q[i].m=q[i].d*1.0/q[i].c;
    }
    sort(q+1,q+1+n,cmp);
    int maxx=0;
    for(int i=1; i<=n; i++)
        for(int j=t; j>=q[i].c; j--)
        {
            dp[j]=max(dp[j],dp[j-q[i].c]+q[i].a-q[i].d*j);
            maxx=max(dp[j],maxx);
        }
    printf("%d\n",maxx);
    return 0;
}



                
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值