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;
    }
    


  • 相关阅读:
    Docker学习笔记07_网络配置
    Docker学习笔记06_部署appache+tomcat+redis+mongo+python
    Docker学习笔记05_部署nginx+php+mysql+phpmyadmin
    Docker学习笔记04_镜像管理
    Docker学习笔记03_容器的简单应用
    Docker学习笔记02_基本操作
    Docker学习笔记01_CentOS 7安装Docker
    Cisco Ironport ESA配置拒收黑名单
    CentOS 7安装Cobra
    jvm内存模型、常见参数及调优
  • 原文地址:https://www.cnblogs.com/herumw/p/9464640.html
Copyright © 2011-2022 走看看