zoukankan      html  css  js  c++  java
  • SDUT 2408:Pick apples

    Pick apples

    Time Limit: 1000MS Memory limit: 165536K

    题目描述

    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.

    输入

    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.

    输出

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

    示例输入

    1
    1 1
    2 1
    3 1
    6

    示例输出

    Case 1: 6

    可以考虑贪心+背包的思想,贪心优先!以防止超时。

    #include<stdio.h>  
    #define max(a,b) (a>b?a:b)  
    int s[4],p[4],kk=1;  
    long long dp[4][1000005];  
    long long dpp(int v)  
    {  
        for(int i=1; i<=3; ++i)  
            for(int j=0; j<=v; ++j)  
            {  
                if(j>=s[i])dp[i][j]=max(dp[i-1][j],dp[i][j-s[i]]+p[i]);  
                else dp[i][j]=dp[i-1][j];  
            }  
        return dp[3][v];  
    }  
    int main()  
    {  
        int t;  
        scanf( "%d",&t );  
        while( t-- )  
        {  
            int maxx=0,v,g=1;  
            for(int i=1; i<=3; i++)  
            {  
                scanf("%d%d",&s[i],&p[i]);  
                g*=s[i];  
            }  
            scanf("%d",&v);  
            for(int i=1; i<=3; ++i)  
                maxx=maxx>g/s[i]*p[i]?maxx:g/s[i]*p[i];  
            long long ans=(long long)(v/g)*maxx;  
            v%=g;  
            ans+=dpp(v);  
            printf("Case %d: %lld
    ",kk++,ans);  
        }  
        return 0;  
    }  


  • 相关阅读:
    测试文件报告
    Bug Variations
    阶段一 问答题2
    阶段一 问答题1
    HeapSort
    Git系列 (01):git clone 速度太慢解决方法
    ES6系列 (03):链判断运算符和Null 判断运算符
    ES6系列 (02):解构赋值
    ES6系列 (01):箭头函数this指向问题
    我忘却了所有,抛却了信仰,舍弃了轮回,只为,那曾在佛前哭泣的玫瑰,早已失去旧日的光泽。
  • 原文地址:https://www.cnblogs.com/im0qianqian/p/5989355.html
Copyright © 2011-2022 走看看