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

CF

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

3 10
100 200 250
5 6 7
2 4 10

Sample Output

254

Hint

Source

“浪潮杯”山东省第八届ACM大学生程序设计竞赛(感谢青岛科技大学)

题意

n

道题目,每一道题都有一个初始分值 ai ,每个单位时间这道题的分数便会减少 di ,而我们可以在 ci 时间内做出这道题而得到分数,求在时间 T

内最多可以获得的分数。


思路

假设每道题做出所需要的时间都为 t

,那么我们一定会选择单位时间内分数消耗最快的题目开始做,因为这样才能保证总的分数不会减少太快。

假设每道题目不自动消耗分数,那么我们一定会选择题目越快做出越好。

于是,综合以上两种因素得出的公式便是 fi=dici

,这样我们实际是希望d越大越在前面,c越小越在前面,现在c取了倒数,使得1/c也是越大越在前面所以直接把f从大到小排序即可,以后便是裸的01背包

code:

#include <bits/stdc++.h>
using namespace std;
struct node{
    int a,d,c;
    double f;
    bool operator < (const node &other)const{
        return f > other.f;
    }
}p[5100];
int dp[5100];
int main(){
    int n,T;
    while(~scanf("%d%d",&n,&T)){
        memset(dp,0,sizeof(dp));
        for(int i = 0; i < n; i++){
            scanf("%d",&p[i].a);
        }
        for(int i = 0; i < n; i++){
            scanf("%d",&p[i].d);
        }
        for(int i = 0; i < n; i++){
            scanf("%d",&p[i].c);
            p[i].f = (double)p[i].d / (double)p[i].c;
        }
        sort(p,p+n);
        int maxx = 0;
        for(int i = 0; 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);
                maxx = max(dp[j],maxx);
            }
        }
        printf("%d\n",maxx);
    }
    return 0;
}



猜你喜欢

转载自blog.csdn.net/codeswarrior/article/details/80184380