Pick apples(大范围贪心,小范围完全背包)
Pick apples
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
/*
* @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(大范围贪心,小范围完全背包)的更多相关文章
- BZOJ 1193 [HNOI2006]马步距离:大范围贪心 小范围暴搜
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1193 题意: 给定起点(px,py).终点(sx,sy).(x,y < 100000 ...
- [BZOJ1193][HNOI2006]马步距离 大范围贪心小范围爆搜
1193: [HNOI2006]马步距离 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1988 Solved: 905[Submit][Statu ...
- [2012山东ACM省赛] Pick apples (贪心,完全背包,枚举)
Pick apples Time Limit: 1000MS Memory limit: 165536K 题目描述 Once ago, there is a mystery yard which on ...
- [2012山东ACM省赛] Pick apples (贪心,全然背包,枚举)
Pick apples Time Limit: 1000MS Memory limit: 165536K 题目描写叙述 Once ago, there is a mystery yard which ...
- SDUT 2408:Pick apples
Pick apples Time Limit: 1000MS Memory limit: 165536K 题目描述 Once ago, there is a mystery yard which on ...
- [C#] string 与 String,大 S 与小 S 之间没有什么不可言说的秘密
string 与 String,大 S 与小 S 之间没有什么不可言说的秘密 目录 小写 string 与大写 String 声明与初始化 string string 的不可变性 正则 string ...
- 详解C语言的htons和htonl函数、大尾端、小尾端
在Linux和Windows网络编程时需要用到htons和htonl函数,用来将主机字节顺序转换为网络字节顺序. 在Intel机器下,执行以下程序 int main(){ printf(" ...
- android:layout_weight越大所占比例越大和越大所占比例越小的两个例子
摘要: 我的技术博客经常被流氓网站恶意爬取转载.请移步原文:http://www.cnblogs.com/hamhog/p/3907146.html,享受整齐的排版.有效的链接.正确的代码缩进.更好的 ...
- 【Linux基础】大B和小b
1.小b(bit) 在计算机科学中,bit(比特)是表示信息的最小单位,叫做二进制位,一般用0和1表示. 2.大B(Byte) Byte叫做字节,由8个位(8bit)组成一个字节(1Byte),用于表 ...
随机推荐
- Codeforce E. Fire
E. Fire time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...
- Sql Server——查询(一)
查询数据就是对数据库中的数据进行筛选显示.显示数据的表格只是一个"虚拟表". 查询 (1)对列的筛选: 1.查询表中所有数据: select * from 表名 ...
- 如何从两个List中筛选出相同的值
问题 现有社保卡和身份证若干,想要匹配筛选出一一对应的社保卡和身份证. 转换为List socialList,和List idList,从二者中找出匹配的社保卡. 模型 创建社保卡类 /** * @a ...
- TCP/IP(七)之玩转HTTP协议
前言 前面一篇的博文简单的介绍了一下属于应用层的HTTP协议,这一篇我将详细的学习HTTP协议,这也是做Web开发中一定要用到的协议.虽然我是做大数据的,但是多学习一点肯定是 没有坏处的.国庆放假7天 ...
- js自执行函数写法
(1)写法1 (function(){ //函数内容 })() (2)写法2 (function(){ //函数内容 }())
- webpack——devtool里的7种SourceMap模式
我们先来看看文档对这 7 种模式的解释: 模式 解释 eval 每个module会封装到 eval 里包裹起来执行,并且会在末尾追加注释 //@ sourceURL. source-map 生成一个S ...
- Win CE 6.0 获取手持机GPS定位1----基础知识 (C#)
一.GPS全球定位系统的组成 (1)GPS卫星(空间部分) 由沿接近环形的地球轨道运行的24颗卫星组成,位于距地表20200千米的高空,均匀分布在6个轨道面上(每个轨道面4颗),轨道倾角55度.此外, ...
- DevOps之域名
唠叨话 关于德语噢屁事的知识点,仅提供精华汇总,具体知识点细节,参考教程网址,如需帮助,请留言. 域名系统DNS(Domain Name System) 关于域名,知识与技能的层次(知道.理解.运用) ...
- OpenSCAD 建模:矿泉水瓶花洒
下载地址:https://github.com/ZhangGaoxing/openscad-models/tree/master/Sprinkle 代码: module screw(r=){ ::]) ...
- win10 uwp BadgeLogo 颜色
本文讲的是在上传应用商店出现BadgeLogo颜色问题,和如何解决,因为我是渣渣,本文可能带有一定的主观性和局限性,说的东西可能不对或者不符合每个人的预期.如果觉得我有讲的不对的,就多多包含,或者直接 ...