zoukankan      html  css  js  c++  java
  • sdut 2408 Pick apples

    Description

    Once ago, there is a mystery yard which only produces three kinds of apples. The number of each kind is infinite. A girl carrying a big bag comes into the yard. She is so surprised because she has never seen so many apples before. Each kind of apple has a size and a price to be sold. Now the little girl wants to gain more profits, but she does not know how. So she asks you for help, and tell she the most profits she can gain.

    Input

    In the first line there is an integer T (T <= 50), indicates the number of test cases.
    In each case, there are four lines. In the first three lines, there are two integers S and P in each line, which indicates the size (1 <= S <= 100) and the price (1 <= P <= 10000) of this kind of apple.

    In the fourth line there is an integer V,(1 <= V <= 100,000,000)indicates the volume of the girl's bag.

    Output

    For each case, first output the case number then follow the most profits she can gain.

    Sample Input

    1
    1 1
    2 1
    3 1
    6
    

    Sample Output

    Case 1: 6

    题意:就是个多重背包,不过物品的种类是固定三种,wi vi,体积给定,使价值最大
    分析:背包很大,物品单个体积很小,可以先考虑贪心,贪心取性价比比较高的,物品要完整取,那么有可能会放弃一些
    性价比高的,加上剩余的体积,取剩余的两种,使得总价值更高,那么假设性价比从大倒小排序后 ,那么si表示i取几个
    s1*w1=s2*w2,这个时候两种物品的体积相同,那么也就是说第二种物品最多取s2-1个,可以相出出s2最大不会大于100
    那么我们枚举性价比不是最高的两种物品个数,剩下的全部区性价比最高的,O(100*100)就能解决问题
  • 相关阅读:
    Java中的toString、equals方法覆写,懒汉式单例模式,及异常处理
    【Java】String类、Object类、包装类总结
    Java接口练习
    Java面向对象测试
    【Java】二叉搜索树的实现操作及应用
    【Java】实现二叉树基本操作、面试题
    SAS--宏变量
    SAS--array
    SAS--do loop until while
    SAS--设置行号、标记
  • 原文地址:https://www.cnblogs.com/jihe/p/6774797.html
Copyright © 2011-2022 走看看