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),用于表 ...
随机推荐
- angularjs的几种常见写法
学习angularjs不久,遇见的angularjs的写法也是很多的感觉,今天就在这里记录一下,还有没见过的,继续学习中... angularjs 常用的几种种写法 1.链式: angular.mod ...
- Dom4J生成xml和包含CDATA问题
在 java注解生成xml和包含CDATA问题里面做了介绍,这里直接贴代码. 1:生成xml的java文件 package com.dufy.test.xml; import java.io.File ...
- 计蒜客 2017 NOIP 提高组模拟赛(四)Day1 T2 小X的密室
https://nanti.jisuanke.com/t/17323 小 X 正困在一个密室里,他希望尽快逃出密室. 密室中有 N 个房间,初始时,小 X 在 1号房间,而出口在 N号房间. 密室的每 ...
- 【转】DSCP 与IP 优先级IP优先级
在IPv4的报文头中,TOS字段是1字节,如下图所示.根据RFC1122的定义,IP优先级(IPPrecedence)使用最高3比特(第0-2比特).+++++++++++++++++++++++++ ...
- Levenshtein Distance + LCS 算法计算两个字符串的相似度
//LD最短编辑路径算法 public static int LevenshteinDistance(string source, string target) { int cell = source ...
- 发布系统Git使用指南 - the Git Way to Use Git
发布系统Git使用指南 --the Git Way to Use Git 背景 有文章曾归纳,Git是一套内容寻址文件系统,意思是,Git的核心是存储键值对^[1]^.显然,这样的形式不利于普通人 ...
- cocos2dx - 环境配置,项目创建
准备工具 cocos2dx当前最新版本:v3.9 官网下载地址: http://www.cocos.com/download/ python 2.7x最新版本:2.7.11 官 ...
- style里的文字 背景 样式以及边框
<style> body{background:#FCC;} .c00 div{ margin:0 auto; padding:0;} #a01{ ...
- SQLyog快捷键汇总
Ctrl+M 创建一个新的连接Ctrl+N 使用当前设置新建连接Ctrl+F4 断开当前连接 对象浏览器 F5 刷新对象浏览器(默认)Ctrl+B 设置焦点于对象浏览器 SQL 窗 ...
- C#如何连接wifi和指定IP
大家好哈,这是我第一次写博客,我也是才大一结束,自学了10多天C#,有不对的欢迎大家指正,最近因为项目的事而被Wifi和IP折磨了很久,后来借用了一下外国人的SimpleWifi.dll 再自己写了一 ...