AcWing 734. 能量石

#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;

const int N = 10010;

struct node {
    int s,e,l;
}ans[N];

bool cmp(node &a, node &b) {
    return a.s * b.l < b.s * a.l;
}

int f[N];
int main() {
    int T, cnt = 1;
    cin >> T;
    while(T--) {
        cout << "Case #" << cnt++ << ": ";
        int n, time = 0;
        cin >> n;
        for(int i = 1; i <= n; ++i) {
            int s, e, l;
            cin >> s >> e >> l;
            ans[i] = node {s, e ,l};
            time += s;
        }
        sort(ans + 1, ans + n + 1, cmp);
        fill(f, f + N, 0);
        f[0] = 0;
        for(int i = 1; i <= n; ++i) {
            for(int j = time; j >= ans[i].s; --j) {
                f[j] = max(f[j], f[j - ans[i].s] + max(0, ans[i].e - (j - ans[i].s) * ans[i].l));
            }
        }
        int res = 0;
        for(int i = 1; i <= time; ++i) res = max(res, f[i]);
        cout << res << endl;
    }
    return 0;
}
posted @ 2022-03-10 15:46  lemonsbiscuit  阅读(30)  评论(0编辑  收藏  举报