山东省赛--CF(01背包+贪心)

14 篇文章 0 订阅

CF

  1000 ms         65536 KiB
Submit Status My Status  Origin

Description

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?

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.

Sample

Input

Copy3 10
100 200 250
5 6 7
2 4 10

Output

Copy254

题意:在最后剩下t时间的时候有n道题需要你解决,每道题解决的得分为ai-di*t,解决第i道题需要ti的时间,求解最终所能得到的最大得分为多少。

题解:首先,若只考虑单位时间的扣分,那一定是先做扣分多的,若只考虑时间,则因为先做耗时少的,综合考虑,可将di/ci排序,建立dp数组,dp[j]表示拿第j个单位时间时能获得的最大点数,dp[j]=max(dp[j],dp[j-p[i].c]+p[i].a-p[i].d*j),01背包装一下就可以了。

#include<stdio.h>
#include <algorithm>
#include<iostream>
#include<string.h>
#include<vector>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<deque>
#include<ctype.h>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<algorithm>
#define ll long long
#define INF 0x3f3f3f3f
#define FAST_IO ios::sync_with_stdio(false)
const double PI = acos(-1.0);
const double eps = 1e-6;
using namespace std;

struct node
{
    int a,d,c;
    double f;
}p[2005];

int cmp(node a,node b)
{
    return a.f>b.f;
}

int dp[5005];

int main()
{
    int n,t;
    cin>>n>>t;

    for(int i=1;i<=n;i++)
        cin>>p[i].a;
    for(int i=1;i<=n;i++)
        cin>>p[i].d;
    for(int i=1;i<=n;i++)
    {
        cin>>p[i].c;
        p[i].f=p[i].d*1.0/p[i].c;
    }

    sort(p+1,p+1+n,cmp);

    int maxl=0;
    for(int i=1;i<=n;i++)
        for(int j=t;j>=p[i].c;j--)
        {
            dp[j]=max(dp[j],dp[j-p[i].c]+p[i].a-p[i].d*j);
            maxl=max(maxl,dp[j]);
        }

    cout<<maxl<<endl;
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值