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. MS SQL SERVER 锁研究记录

    首先创建一直数据表 ChenJi,有如下字段: ID, DanWeiID,  Name,  ChenJi CREATE TABLE [dbo].[ChenJi]( [ID] [int] NOT NUL ...

  2. system(linux) power on note

    读詹荣开文档摘 BIOS 在完成硬件检测和资源分配后,将硬盘 MBR 中的 Boot Loader 读到系统的 RAM 中,然后将控制权交给 OS Boot Loader Boot Loader执行全 ...

  3. CPU虚拟化技术(留坑)

    留坑~~~ 不知道这个是这么实现的 CPU虚拟化技术就是单CPU模拟多CPU并行,允许一个平台同时运行多个操作系统,并且应用程序都可以在相互独立的空间内运行而互不影响,从而显著提高计算机的工作效率.虚 ...

  4. JAVA字符串的GZIP压缩解压缩

    package com.gzip; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import ...

  5. 学习OpenCV——Kmean(C++)

    从前也练习使用过OpenCV的Kmean算法,但是那版本低,而且也是基于C的开发.这两天由于造论文的需要把它重新翻出来在研究一下C++,发现有了些改进 kmeans C++: doublekmeans ...

  6. 去掉字符串中的空格 JS JQ 正则三种不同写法

    <script> function trim(str) { return str.replace(/(^\s*|\s*$)/g, "") } console.log(t ...

  7. paper 50 :人脸识别简史与近期进展

    自动人脸识别的经典流程分为三个步骤:人脸检测.面部特征点定位(又称Face Alignment人脸对齐).特征提取与分类器设计.一般而言,狭义的人脸识别指的是"特征提取+分类器"两 ...

  8. 2. 星际争霸之php面向对象(二)

    题记==============================================================================本php设计模式专辑来源于博客(jymo ...

  9. 必备的 Java 参考资源列表(转)

    包含必备书籍.站点.博客.活动等参考资源的完整清单级别: 初级 Ted Neward, 主管,ThoughtWorks, Neward & Associates 2009 年 3 月 02 日 ...

  10. servlet、genericservlet、httpservlet之间的区别(转)

    当编写一个servlet时,必须直接或间接实现servlet接口,最可能实现的方法就是扩展javax.servlet.genericservlet或javax.servlet.http.httpser ...