CF----思维排序+01背包 山东省第八届省赛K题

本文解析了一个CF风格的比赛问题,涉及动态规划与贪心算法。通过分析比赛规则与得分计算方式,给出了具体的解题思路和排序策略,最终实现01背包算法求解最大得分。

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大学生程序设计竞赛(感谢青岛科技大学)
题目链接:http://www.sdutacm.org/onlinejudge2/index.php/Home/Contest/contestproblem/cid/2081/pid/3903


其实这个题该属于贪心+dp的,比赛的时候死活没想出来。

这个题的意思是说根据cf的规则,我们先定义这场比赛的总时长为T,然后每一个题目有一个分数,有一个增长系数di,解出来这个题目需要ci的时间,现在问你在这场比赛中最多可以获得多少分

首先这个题有顺序关系,所以我们要先确定顺序,我们来排序两个题A和B,如果A在B的前面,损失的分就是(Ca)*da+(Ca+Cb)*db,如果B放在前面就是(Cb)*db+(Cb+Ca)*da,然后根据这个排序就可以了,然后就会发现d是越大越靠前,c是越小越靠前。所以我们用x[i].b/x[i].c排序。

最后我们跑一下01背包取一下最优策略就好了。

代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
struct node{
    int a,b,c;
    double f;
}x[2009];
int dp[5009];
bool cmp(struct node a,struct node b){
    return a.f>b.f;
}
int main(){
    int n,t;
    scanf("%d%d",&n,&t);
    memset(dp,0,sizeof(dp));
    for(int i=1;i<=n;i++)
        scanf("%d",&x[i].a);
    for(int i=1;i<=n;i++)
        scanf("%d",&x[i].b);
    for(int i=1;i<=n;i++)
        scanf("%d",&x[i].c);
    for(int i=1;i<=n;i++)
        x[i].f=1.0*x[i].b/x[i].c;
    sort(x+1,x+n+1,cmp);
    int mix=0;
    for(int i=1;i<=n;i++){
        for(int j=t;j>=x[i].c;j--){
            dp[j]=max(dp[j],dp[j-x[i].c]+x[i].a-x[i].b*j);
            mix=max(dp[j],mix);
        }
    }
    printf("%d\n",mix);
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值