Pick apples

Time Limit: 1000MS Memory Limit: 165536KB

Problem 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.

Example Input

1
1 1
2 1
3 1
6

Example Output

Case 1: 6

Hint

 

Author

2012年"浪潮杯"山东省第三届ACM大学生程序设计竞赛
/*
* @Author: lyuc
* @Date: 2017-04-27 16:06:19
* @Last Modified by: lyuc
* @Last Modified time: 2017-04-27 19:27:24
*/ #include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define LL long long
#define maxn 1000000
using namespace std;
struct node{
int s,p;
bool operator <(const node & other) const {
return p*1.0/s>other.p*1.0/other.s;
}
}fr[];
LL dp[];
int t;
int v;
LL res;
int main(){
// freopen("in.txt","r",stdin);
scanf("%d",&t);
for(int ca=;ca<=t;ca++){
printf("Case %d: ",ca);
res=;
memset(dp,,sizeof dp);
for(int i=;i<;i++){
scanf("%d%d",&fr[i].s,&fr[i].p);
}
scanf("%d",&v);
if(v<=maxn){
for(int i=;i<;i++){
for(int j=fr[i].s;j<=v;j++){
dp[j]=max(dp[j],dp[j-fr[i].s]+fr[i].p);
}
}
printf("%lld\n",dp[v]);
}else{
sort(fr,fr+);
while(v>maxn){
res+=fr[].p;
v-=fr[].s;
}
for(int i=;i<;i++){
for(int j=fr[i].s;j<=v;j++){
dp[j]=max(dp[j],dp[j-fr[i].s]+fr[i].p);
}
}
printf("%lld\n",res+dp[v]);
}
}
return ;
}

Pick apples(大范围贪心,小范围完全背包)的更多相关文章

  1. BZOJ 1193 [HNOI2006]马步距离:大范围贪心 小范围暴搜

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1193 题意: 给定起点(px,py).终点(sx,sy).(x,y < 100000 ...

  2. [BZOJ1193][HNOI2006]马步距离 大范围贪心小范围爆搜

    1193: [HNOI2006]马步距离 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1988  Solved: 905[Submit][Statu ...

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

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

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

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

  5. SDUT 2408:Pick apples

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

  6. [C#] string 与 String,大 S 与小 S 之间没有什么不可言说的秘密

    string 与 String,大 S 与小 S 之间没有什么不可言说的秘密 目录 小写 string 与大写 String 声明与初始化 string string 的不可变性 正则 string ...

  7. 详解C语言的htons和htonl函数、大尾端、小尾端

    在Linux和Windows网络编程时需要用到htons和htonl函数,用来将主机字节顺序转换为网络字节顺序. 在Intel机器下,执行以下程序 int main(){   printf(" ...

  8. android:layout_weight越大所占比例越大和越大所占比例越小的两个例子

    摘要: 我的技术博客经常被流氓网站恶意爬取转载.请移步原文:http://www.cnblogs.com/hamhog/p/3907146.html,享受整齐的排版.有效的链接.正确的代码缩进.更好的 ...

  9. 【Linux基础】大B和小b

    1.小b(bit) 在计算机科学中,bit(比特)是表示信息的最小单位,叫做二进制位,一般用0和1表示. 2.大B(Byte) Byte叫做字节,由8个位(8bit)组成一个字节(1Byte),用于表 ...

随机推荐

  1. Jquery一些常用的方法

    整理以前的笔记,在学习JavaScript时候,经常会用到一些方法,但是有时忘掉了具体用法,因此记下.方便以后查阅. 这篇博文先说明这些方法的用途: removeClass().remove().cs ...

  2. BZOJ1207_打鼹鼠_KEY

    [HNOI2004]打鼹鼠 Time Limit: 10 Sec Memory Limit: 162 MB Description 鼹鼠是一种很喜欢挖洞的动物,但每过一定的时间,它还是喜欢把头探出到地 ...

  3. LinkedHashMap 源码解析

    概述: LinkedHashMap实现Map继承HashMap,基于Map的哈希表和链该列表实现,具有可预知的迭代顺序. LinedHashMap维护着一个运行于所有条目的双重链表结构,该链表定义了迭 ...

  4. Relocation 状态压缩DP

     Relocation Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit  ...

  5. Centos7 创建本地 docker 仓库极其遇到的问题

    环境安装: VirtualBox 安装 Centos7 安装 docker 1. 配置私有仓库和客户端地址 私有仓库:192.168.1.104 客户端:192.168.1.103 通过 Centos ...

  6. TargetType Mismatch

    TargetType Mismatch 环境:windowsphone 8,silerlight toolkit, 页面报TargeType Mismatch错误或者 length 0,是因为Syst ...

  7. MongoDB数据库的安装、配置和使用

    1.下载安装包   wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.4.7.tgz 2.解压安装包   tar -zxf mo ...

  8. MySQL Windows版安装详解

    一.下载MySQL MySQL官网https://dev.mysql.com提供了Windows下的安装版msi和解压版zip,其中均包含32和64位版本,mis版本与SqlServer安装基本一致N ...

  9. Ubuntu16.04 install mysql5.X

    打开终端: Ctrl+Alt+T 安装ubuntu自带的mysql-server: sudo apt-get install mysql-server 输出Y按回车如下图: 默认安装为root用户,所 ...

  10. Python实战之SocketServer模块

    文章出处:http://www.cnblogs.com/wupeiqi/articles/5040823.html SocketServer内部使用 IO多路复用 以及 "多线程" ...