SDUT 2408:Pick apples

322人阅读 评论(0) 收藏 举报
分类:

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\n",kk++,ans);  
    }  
    return 0;  
}  


查看评论

SDUT 2408 Pick apples

Pick apples Time Limit: 1000ms   Memory limit: 165536K  有疑问?点这里^_^ 题目描述   Once ago, there ...
  • u012161037
  • u012161037
  • 2013-09-18 15:20:31
  • 506

SDUT:2408 Pick apples(贪心+完全背包)

题意:给一个大小为v的包,有三种苹果,分别给其价值和体积,问最多可装多少价值。 思路:v高达10^8,直接完全背包是不行的。由于一共三种苹果,可以考虑优化。在苹果体积是三种苹果体积的乘积时,取可以得...
  • kkkwjx
  • kkkwjx
  • 2015-04-18 17:07:53
  • 411

Pick apples(动态规划,难点背包容量太大)

1、点击打开链接Pick apples //每种物品的最大重量是100,要求的这个数m应该是三种物品重量的最小公倍数 2、题目大意: 有三种苹果,每种苹果都有其重量和价值,且苹果数量都是无限个,...
  • sdjzping
  • sdjzping
  • 2013-02-25 19:48:11
  • 1377

[2012山东ACM省赛] Pick apples (贪心,完全背包,枚举)

Pick apples Time Limit: 1000MS Memory limit: 165536K 题目描述 Once ago, there is a mystery yard whic...
  • sr19930829
  • sr19930829
  • 2014-04-28 14:13:57
  • 2123

2013山东省第三届ACM省赛 Pick apples

Pick apples Time Limit: 1000MS Memory limit: 165536K 题目描述 Once ago, there is a mystery yard whic...
  • u014552756
  • u014552756
  • 2016-04-30 18:49:30
  • 287

SDUT 2408 Pick apples 贪心+背包(大容量背包)

点击打开链接 种苹果,每种都有对应的Size,Value,给你一个背包空间,求最大的价值。 ///贪心+背包 /// 先对大容量尽可能装性价比最高的, 然后剩余的容量(比任何单个物品的容量都大...
  • became_a_wolf
  • became_a_wolf
  • 2016-03-22 18:38:45
  • 290

Pick apples

Pick apples Time Limit: 1000MS Memory limit: 165536K 题目描述 Once ago, there is a mystery yard whi...
  • YXianXeng
  • YXianXeng
  • 2017-08-16 10:09:30
  • 121

Pick Apples

Problem Description A long time ago, there was another Garden of Eden which produces three kinds ...
  • ggemini
  • ggemini
  • 2013-04-13 14:04:05
  • 482

SDUT 2408 Pick apples(完全背包+贪心)2012年"浪潮杯"山东省第三届ACM大学生程序设计竞赛

题目大意:给定3中物品,每种无限多,接下来三行分别为没见物品的体积,价格。思路:直接背包肯定不行,这样我们就可以对容积在三个数的体积的最小公倍数以内的容量进行背包,以外的我们可以对超出的部分进行贪心。...
  • Grit_ICPC
  • Grit_ICPC
  • 2016-03-20 19:36:21
  • 359

sdut2408 Pick apples

Pick apples Time Limit: 1000ms   Memory limit: 165536K  有疑问?点这里^_^ 题目描述 Once ago, there i...
  • a197p
  • a197p
  • 2015-04-12 22:59:00
  • 402
    个人资料
    专栏达人 持之以恒
    等级:
    访问量: 37万+
    积分: 1万+
    排名: 2000
    寻找 Qianqian 遇见 就是幸运
    博客专栏
    最新评论