山东省第八届ACM省赛 K 题 CF (排序01背包)

本文介绍了一道ACM竞赛中的题目,涉及动态规划和排序策略。题目要求计算在限定时间内,根据每道题的初始分数、递减分数和解题时间,确定最佳解题顺序以获取最高总分。解题思路包括对题目进行排序,通过比较不同题目得分减少的速度来确定解题顺序。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


Problem Description

LYD loves codeforces since there are many Russian contests. In an contest lasting for T minutes there are n problems, and for theith 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.

Example Input
3 10
100 200 250
5 6 7
2 4 10
Example Output
254

题意:LYD要打CF,一共n道题,t单位时间,每道题都有初始分数a,每单位时间减的分数d和做出这道题需要多长时间c,求最大的得分;

思路:这题不是跟以前的背包一样,这题后面选的每个东西都跟前面有关的。。前面的那种背包无关顺序,所以这种肯定要排个序,如果是无序的,这个最优过程中选的也不一定按照最优顺序的。。只是这种顺序的最优解,比如   11 1 1 ,11 1 10从前往后分别是11分, 1分钟做完,每秒掉1/10分,这也最优就是10分,第二个都成了0分,如果第一个在前面 就不一样了。。

然后按照怎样的顺序排序呢

假设有两个题, 第一个题 a.c a.d 第二个题 b.c b.d 两种顺序减得分分别是 a.c*a.d+(b.c+a.c)*b.d 〈 b.c*b.d+(b.c+a.c)*a.d 化简就是a.c/a.d < b.c/b.d


真的不想提省赛,这也是个套路题,比赛最后40分钟我背包,排序我都想到了,但没具体深想,然后就被队友叫去找规律了。。这是离金牌最近的一次,却出了事故,呵呵,之后的比赛加油!

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 1e6 + 5;
int dp[maxn];
struct node
{
    int d, c, t;
    double f;
}a[2000+5];
int cmp(node a, node b)
{
    return a.f < b.f;
}
int main()
{
    int n, t;
    while(~scanf("%d%d", &n, &t))
    {
        memset(dp, 0, sizeof(dp));
        for(int i = 1; i <= n; i++)
            scanf("%d", &a[i].t);
        for(int i = 1; i <= n; i++)
            scanf("%d", &a[i].d);
        for(int i = 1; i <= n; i++)
            scanf("%d", &a[i].c), a[i].f = a[i].c*1.0 / a[i].d;
        sort(a+1, a+1+n, cmp);
        int maxx = 0;
        for(int i = 1; i <= n; i++)
        {
            for(int v = t; v >= a[i].c; v--)
            {
                dp[v] = max(dp[v], dp[v-a[i].c]+a[i].t-a[i].d*v);
                maxx = max(dp[v], maxx);  //在过程中取最大值,因为不一定t分钟都用上
            }
        }
        printf("%d\n", maxx);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值