【hautoj1307】CF

来源:互联网 发布:java axis2 webservice 编辑:程序博客网 时间:2024/05/16 09:53

传送门:点击打开链接

题目描述

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 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?

输入

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 an integer in a single line, indicating the maximum points LYD can get.

样例输入

3 10
100 200 250
5 6 7
2 4 10

样例输出

254


题意:
输入n,t,代表n道题 时间为t,第二行a每道题分值,第三行d每分钟失的分,最后一行c完成这道题的用时。求最多得几分。

思路:
先做失分最多的题,先做用时最短的题,结合一下先做失分最多又用时最短的题,即d/c最大的先做,排序。

之后就是01背包,注意dp[n]不一定是最大,因为还要失分。
说一下为什么要排序...如果直接按01做,选的题目不会变,无外乎就是先选后选的问题,问题就出在这,先选后选对于本题来说至关重要....


代码:
#include <bits/stdc++.h>using namespace std;typedef long long LL;struct node{    int a,c,d;    double m;} q[2005];bool cmp(node x,node y){    if(x.m==y.m)        return x.c<y.c;    return x.m>y.m;}int dp[5005];int main(){    int i,n,t;    cin>>n>>t;    for(i=1; i<=n; i++) scanf("%d",&q[i].a);    for(i=1; i<=n; i++) scanf("%d",&q[i].d);    for(i=1; i<=n; i++)    {        scanf("%d",&q[i].c);        q[i].m=q[i].d*1.0/q[i].c;    }    sort(q+1,q+1+n,cmp);    int maxx=0;    for(int i=1; i<=n; i++)        for(int j=t; j>=q[i].c; j--)        {            dp[j]=max(dp[j],dp[j-q[i].c]+q[i].a-q[i].d*j);            maxx=max(dp[j],maxx);        }    printf("%d\n",maxx);    return 0;}


 
原创粉丝点击