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的更多相关文章

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

    Pick apples Time Limit: 1000MS Memory limit: 165536K 题目描述 Once ago, there is a mystery yard which on ...

  2. Pick apples(大范围贪心,小范围完全背包)

    Pick apples Time Limit: 1000MS Memory Limit: 165536KB Submit Statistic Discuss Problem Description O ...

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

    Pick apples Time Limit: 1000MS Memory limit: 165536K 题目描写叙述 Once ago, there is a mystery yard which ...

  4. 10年省赛-Greatest Number (二分+暴力) + 12年省赛-Pick apples(DP) + UVA 12325(暴力-2次枚举)

    题意:给你n个数,在里面取4个数,可以重复取数,使和不超过M,求能得到的最大的数是多少: 思路:比赛时,和之前的一个题目很像,一直以为是体积为4(最多选择四次)的完全背包,结果并不是,两两求和,然后二 ...

  5. sdut2408 pick apples (贪心+背包)山东省第三届ACM省赛

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/svitter/article/details/24642587 本文出自:http://blog.c ...

  6. 山东省第三届ACM省赛

    Solved ID PID Title Accepted Submit   A 2407 Impasse (+) 0 0   B 2415 Chess 0 0   C 2414 An interest ...

  7. hdu5303Delicious Apples

    题意大概就是有n框苹果放在长度为L的环上,每框有ai个苹果.你有一个容量为k的框.要你从0点处出发,随意走.框满了就回到0点把苹果放在那里.继续走直到把苹果都拿完为止.问你最少要走多少路程. 首先贪心 ...

  8. hdu多校第4场 B Harvest of Apples(莫队)

    Problem B. Harvest of Apples Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Su ...

  9. Problem B. Harvest of Apples HDU - 6333(莫队)

    Problem Description There are n apples on a tree, numbered from 1 to n.Count the number of ways to p ...

随机推荐

  1. Java基础之在窗口中绘图——绘制直线和矩形(Sketcher 2 drawing lines and rectangles)

    控制台程序. import javax.swing.JComponent; import java.util.*; import java.awt.*; import java.awt.geom.*; ...

  2. Leetcode: Water and Jug Problem && Summary: GCD求法(辗转相除法 or Euclidean algorithm)

    You are given two jugs with capacities x and y litres. There is an infinite amount of water supply a ...

  3. stucts2 基础程序

    参考<Struts2+Hibernate+Spring> index.jsp

  4. Spring的2个思想

    IOC:控制反转 反转:获取依赖对象的方式被反转了 控制反转是关于一个对象如何获取他所依赖的对象的引用,反转是指责任的反转. (1)对象实例化问题(Spring完成) 传统的依赖方式:程序员实例化 ( ...

  5. 实现listview的条目点击后改变背景颜色

    gv_categoryeffect_gridview.setChoiceMode(GridView.CHOICE_MODE_SINGLE);,再设置一个selector的背景选择器 getResour ...

  6. angularjs---$http.post发的数据,后台取不到

    我用$http.post(url, data). 后台用play框架,不知道为什么总是取不到data数据.如果直接用$.post(url, data); 就可以! 后台Play的一个action: 打 ...

  7. 夺命雷公狗---node.js---3commonJs 与 nodeJs的简介

    JavaScript是一个强大面向对象语言,它有很多快速高效的解释器.官方JavaScript标准定义的API是为了构建基于浏览器的应用程序.然而,并没有定于一个用于更广泛的应用程序的标准库. Com ...

  8. libSVM 简易使用手册

    关于SVM的基础理论知识,可以google这篇文章<SVM的八股简介>,讲解得生动有趣,是入门的极好教材.作为拿来主义者,我更关心怎么用SVM,因此瞄上了台湾林智仁教授提供的libSVM. ...

  9. [MaxOSX] 路由操作

    查看当前路由情况 netstat -nr 添加路由 sudo route -n add x.x.x.x/24 x.x.x.x 可以简单这样子理解: 第1个参数 x.x.x.x/24是远程地址 第2个参 ...

  10. yii2获取登陆的用户名

    yii2获取登陆的用户名: yii::$app->user->identity->username; 判断用户名是否登陆 if(Yii::$app->user->isGu ...