zoukankan      html  css  js  c++  java
  • hdu5501 The Highest Mark

    Problem Description
    The SDOI in 2045 is far from what it was been 30 years ago. Each competition has t minutes and n problems.

    The ith problem with the original mark of Ai(Ai106),and it decreases Bi by each minute. It is guaranteed that it does not go to minus when the competition ends. For example someone solves the ith problem after x minutes of the competition beginning. He/She will get AiBix marks.

    If someone solves a problem on x minute. He/She will begin to solve the next problem on x+1 minute.

    dxy who attend this competition with excellent strength, can measure the time of solving each problem exactly.He will spend Ci(Cit) minutes to solve the ith problem. It is because he is so godlike that he can solve every problem of this competition. But to the limitation of time, it's probable he cannot solve every problem in this competition. He wanted to arrange the order of solving problems to get the highest mark in this competition.
     

    Input
    There is an positive integer T(T10) in the first line for the number of testcases.(the number of testcases with n>200 is no more than 5)

    For each testcase, there are two integers in the first line n(1n1000) and t(1t3000) for the number of problems and the time limitation of this competition.

    There are n lines followed and three positive integers each line Ai,Bi,Ci. For the original mark,the mark decreasing per minute and the time dxy of solving this problem will spend.


    Hint:
    First to solve problem 2 and then solve problem 1 he will get 88 marks. Higher than any other order.
     

    Output
    For each testcase output a line for an integer, for the highest mark dxy will get in this competition.
     

    Sample Input
    1 4 10 110 5 9 30 2 1 80 4 8 50 3 2
     

    Sample Output
    88
     

    Source
     

    这题是贪心和背包问题,首先考虑如果已经确定要做的题,那么怎样的做题顺序能使分数减少最少,这里我们假设有i和i+1,那么如果先做i后做i+1,分数减少c[i+1]*b[i]+K(K是常数),否则分数减少c[i]*b[i+1]+K.那么如果是第二种减少的少,则c[i]*b[i+1]<c[i+1]*b[i],即c[i+1]/b[i+1]>c[i]/b[i],所以如果对于相邻的两个数,如果c[i+1]/b[i+1]>c[i]/b[i],那么就要交换顺序,这样我们就可以排个序,然后背包就行了。


    #include<iostream>
    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    #include<math.h>
    #include<vector>
    #include<map>
    #include<set>
    #include<queue>
    #include<stack>
    #include<string>
    #include<algorithm>
    using namespace std;
    #define ll int
    #define inf 0x7fffffff
    #define maxn 1006
    struct node{
        int a,b,c;
        double num;
    }d[maxn];
    int dp[4*maxn];
    bool cmp(node a,node b){
        return a.num<b.num;
    }
    
    
    int main()
    {
        int n,m,i,j,T;
        scanf("%d",&T);
        while(T--)
        {
            scanf("%d%d",&n,&m);
            for(i=1;i<=n;i++)
            {
                scanf("%lld%lld%lld",&d[i].a,&d[i].b,&d[i].c);
                d[i].num=(double)d[i].c/(double)d[i].b;
    
            }
            sort(d+1,d+1+n,cmp);
            memset(dp,0,sizeof(dp));
            for(i=1;i<=n;i++){
                for(j=m;j>=d[i].c;j--){
                    dp[j]=max(dp[j],dp[j-d[i].c ]+d[i].a-j*d[i].b);
                }
            }
            int maxx=-1;
            for(i=1;i<=m;i++)maxx=max(maxx,dp[i]);
            printf("%d
    ",maxx);
        }
        return 0;
    }
    


  • 相关阅读:
    解决asp.net丢失session的方法文件
    Asp.net 从客户端中检测到有潜在危险的Request.Form值
    解决 ORA-12154 TNS无法解析指定的连接标识符
    sys用户权限不足,本地登录失败 |ORA-01031 insufficient privileges|
    Android按钮单击事件处理的几种方法(Android学习笔记)
    百度地图自定义放大缩小按钮
    百度地图 JS API开发Demo01
    java微信授权登录传参给redirect_uri 接口,回到原页面,传递多个参数
    利用padding-top/padding-bottom百分比,进行占位和高度自适应
    Rotate Array 旋转数组 JS 版本解法
  • 原文地址:https://www.cnblogs.com/herumw/p/9464640.html
Copyright © 2011-2022 走看看