山东省第八届ACM省赛 CF(贪心+01背包)

13 篇文章 0 订阅
13 篇文章 0 订阅

Problem 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 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 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<ai6000). ( 0 < a i ≤ 6000 ) .
The third line contains n integers d1,d2,..,dn (0<di50). ( 0 < d i ≤ 50 ) .
The forth line contains n integers c1,c2,..,cn (0<ci400). ( 0 < c i ≤ 400 ) .

Output

Output an integer in a single line, indicating the maximum points LYD can get.

Sample Input

3 10
100 200 250
5 6 7
2 4 10

Sample Output

254

题目描述

在T时间内有n个题目,题目的初始分数为ai,从比赛开始每分钟掉di分,LYD可以用ci分钟做出该题,问LYD的得分最高可以得多少.

解题思路

dici d i c i 为优先级贪心排序,然后01背包.
字面理解:题目做出来的越快越好,单位时间内减少的分数越小越好,即 dc d c 越小越好.
脑洞比较复杂的理解:
现有A、B两个题目
若是先做A,减少的时间为: ta=cada+(ca+cb)db=cada+cbdb+cadb t a = c a ∗ d a + ( c a + c b ) ∗ d b = c a ∗ d a + c b ∗ d b + c a ∗ d b
若是先做B,减少的时间为: tb=cbdb+(cb+ca)da=cada+cbdb+cbda t b = c b ∗ d b + ( c b + c a ) ∗ d a = c a ∗ d a + c b ∗ d b + c b ∗ d a
假设选择A更好,那么 ta t a 越小 tb t b 越大,A的优先级就越高,根据上式则有 ca c a 越小越好, da d a 越大越好.

代码实现

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
#define IO ios::sync_with_stdio(false);\
cin.tie(0);\
cout.tie(0);
const int maxn = 2e3+7;
int dp[5007];
struct node
{
    int a;
    int d;
    int c;
    double f;
    bool operator < (const node& no)const{
        return f > no.f;
    }
}num[maxn];
int main()
{
    IO;
    int n,t;
    cin>>n>>t;
    for(int i=0;i<n;i++)
        cin>>num[i].a;
    for(int i=0;i<n;i++)
        cin>>num[i].d;
    for(int i=0;i<n;i++)
    {
        cin>>num[i].c;
        num[i].f=(double)num[i].d/(double)num[i].c;
    }
    sort(num,num+n);
    int ans=-1;
    for(int i=0;i<n;i++)
    {
        for(int j=t;j>=num[i].c;j--)
        {
            dp[j]=max(dp[j],dp[j-num[i].c]+num[i].a-num[i].d*j);
            ans=max(ans,dp[j]);
        }
    }
    cout<<ans<<endl;
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值