贪心+dp hdu5501 The Highest Mark

传送门:点击打开链接

题意:类似cf的赛制,每道题目有A,B,C三个值,A表示初始分数,B表示每分钟题的分数会减少B,C表示做这道题需要C分钟,数据保证分数不会变为负数。现在给出比赛时长,问安排做题的顺序,求最大得分。

思路:这道题是一道非常经典的题。首先很容易想到一件事,给出的题哪个先做没有先后顺序,那么在动态规划的时候,必然有前后顺序,所以要么就是状态压缩,要么就是之前就把这些题目排序了,使得后面是有序的。状压不用考虑了因为数据太大,所以我们考虑要如何排序。

现在有A1,B1,C1和A2,B2,C2这两道题,如果先做1再做2的得分是A1-B1*C1+A2-B2*(C1+C2),如果先做2在做1的得分是A2-B2*C2+A1-B1*(C1+C2),令先做1再做2的得分更高些,那么有A1-B1*C1+A2-B2*(C1+C2) >= A2-B2*C2+A1-B1*(C1+C2),解得B1*C2>=B2*C1

所以,只要B1*C2>=B2*C1,那么先做题1再做题2的分数就会更高。

所以,我们只需要根据这个来排序,再做dp,就能得到答案了.

#include<map>
#include<set>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<cstdio>
#include<cctype>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#define fuck printf("fuck")
#define FIN freopen("input.txt","r",stdin)
#define FOUT freopen("output.txt","w+",stdout)
using namespace std;
typedef long long LL;

const int MX = 3000 + 5;

int T, n, m;
int dp[MX];

struct Data {
    int a, b, c;
    Data() {}
    Data(int _a, int _b, int _c) {
        a = _a; b = _b; c = _c;
    }
    bool operator<(const Data &P) const {
        return (LL)b * P.c > (LL)P.b * c;
    }
} D[MX];

int main() {
    //FIN;
    scanf("%d", &T);
    while(T--) {
        memset(dp, 0, sizeof(dp));
        scanf("%d%d", &n, &m);

        for(int i = 1; i <= n; i++) {
            scanf("%d%d%d", &D[i].a, &D[i].b, &D[i].c);
        }
        sort(D + 1, D + 1 + n);

        for(int i = 1; i <= n; i++) {
            for(int j = m; j >= D[i].c; j--) {
                dp[j] = max(dp[j], dp[j - D[i].c] + D[i].a - D[i].b * j);
            }
        }
        int ans = 0;
        for(int i = 0; i <= m; i++) {
            ans = max(ans, dp[i]);
        }
        printf("%d\n", ans);
    }
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值