山东生第八届acm省赛 cf

本文介绍了一种CF比赛中问题解答的优化策略,通过合理安排解题顺序以最大化得分。利用01背包思想结合动态规划,根据题目特性进行排序,实现最优解。

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



CF

Time Limit: 1000MS  Memory Limit: 65536KB
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 aiditipoints, 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
Hint
Author
“浪潮杯”山东省第八届ACM大学生程序设计竞赛(感谢青岛科技大学)

题意:主角打cf比赛 他有n道题 且他一共有t的时间来做这些题 a1到an是这n道题做出来后相应的分数 d1到dn是这n到题从开始到做出花费的时间里每分钟要扣除的分数 c1到cn是这每道题做出需要花费的时间 要求算出他所能湖的的最大分数

这道题在比赛的时候作为最后时间内尝试的题目 用了10分钟套了一个01背包的板子 当然肯定错了 后来补题又看到了这道题 可是还是想不出来解决的办法 这道题和普通的01背包区别在多了一个罚时 可是在规划的比较公式内得分减去罚时也不对 后来百度 看见百度上说在进行规划之前要先进行对题目的优先顺序排序 。

具体的排序规则:

假设有两个题, 第一个题 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

ac代码:
#include <iostream>  
#include <cstdio>  
#include <cstring>  
#include <algorithm>  
using namespace std;  
const int maxn = 1e6 + 5;  
int dp[maxn];  //开一个很大的dp数组 用来动态规划存储需比较的数据
struct node  
{  
    int d, c, t;  //定义一个结构体a d为本题分数 c为罚时扣分 t为题目需要花费的时间
    double f;  //f为c/d 用来排序的要素
}a[2000+5];  
int cmp(node a, node b)  
{  
    return a.f < b.f;  //用来排序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;  //f的值
        sort(a+1, a+1+n, cmp);  //根据f进行排序
        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);  //dp的比较过程
                maxx = max(dp[v], maxx);  //在过程中取最大值,因为不一定t分钟都用上 因为可能存在你做出一道题得到的分数比这道题的罚时分少 所以不做这道题时的分数更多
            }  
        }  
        printf("%d\n", maxx);  
    }  
    return 0;  
}  

CF

Time Limit: 1000MS  Memory Limit: 65536KB
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 aiditipoints, 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
Hint
Author
“浪潮杯”山东省第八届ACM大学生程序设计竞赛(感谢青岛科技大学)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值