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

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 < a i 6000 ) .
The third line contains n integers d1,d2,..,dn ( 0 < d i 50 ) .
The forth line contains n integers c1,c2,..,cn ( 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的得分最高可以得多少.

解题思路

d i c i 为优先级贪心排序,然后01背包.
字面理解:题目做出来的越快越好,单位时间内减少的分数越小越好,即 d c 越小越好.
脑洞比较复杂的理解:
现有A、B两个题目
若是先做A,减少的时间为: 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,减少的时间为: 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更好,那么 t a 越小 t b 越大,A的优先级就越高,根据上式则有 c a 越小越好, 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;
}

猜你喜欢

转载自blog.csdn.net/so_so_y/article/details/80062226