第八届山东省acm省赛dp

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
借鉴解析 https://blog.csdn.net/qq_34374664/article/details/71747308

题意: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

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,t;

struct node
{
    int t,d,c;
    double f;

}ff[2005];
bool cmp(node a,node b)
{
    return a.f<b.f;
}
int dp[5000];

int main()
{
    while(cin>>n>>t)
    {memset(dp,0,sizeof(dp));
        for(int i=1;i<=n;++i)
        {
            scanf("%d",&ff[i].t);
        }
          for(int i=1;i<=n;++i)
        {
            scanf("%d",&ff[i].d);
        }
          for(int i=1;i<=n;++i)
        {
            scanf("%d",&ff[i].c);ff[i].f=ff[i].c*1.0/ff[i].d;
        }
        sort(ff+1,ff+n+1,cmp);
        int maxn=0;
        for(int i=1;i<=n;++i)
        {
            for(int v=t;v>=ff[i].c;--v)
            {
                dp[v]=max(dp[v],dp[v-ff[i].c]+ff[i].t-ff[i].d*v);
                maxn=max(dp[v],maxn);
            }
        }
        cout<<maxn<<endl;
    }

    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值