博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Pick apples(大范围贪心,小范围完全背包)
阅读量:7070 次
发布时间:2019-06-28

本文共 2486 字,大约阅读时间需要 8 分钟。

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

11 12 13 16

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 
#include
#include
#include
#define LL long long#define maxn 1000000using 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[4];LL dp[1000005];int t;int v;LL res;int main(){ // freopen("in.txt","r",stdin); scanf("%d",&t); for(int ca=1;ca<=t;ca++){ printf("Case %d: ",ca); res=0; memset(dp,0,sizeof dp); for(int i=0;i<3;i++){ scanf("%d%d",&fr[i].s,&fr[i].p); } scanf("%d",&v); if(v<=maxn){ for(int i=0;i<3;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+3); while(v>maxn){ res+=fr[0].p; v-=fr[0].s; } for(int i=0;i<3;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 0;}

 

转载于:https://www.cnblogs.com/wuwangchuxin0924/p/6776151.html

你可能感兴趣的文章
浅谈HDFS的读流程
查看>>
【探索】VS下虚继承实现的方法-1
查看>>
Java基础加密之MD5加密算法
查看>>
盛夏光年
查看>>
Android 沉浸式状态栏(像IOS那样的状态栏与应用统一颜色样式)
查看>>
RHCS集群服务 7.10
查看>>
windows 使用vnc图形化界面远程连接阿里云ubuntu 16.04云服务器
查看>>
linux和CentOS是什么关系;CentOS和RHEL是什么关系
查看>>
samba
查看>>
利用Python网络爬虫抓取微信好友的签名及其可视化展示
查看>>
Linux-Nginx代理
查看>>
计算机的系统组成简介---运维笔记
查看>>
Liunx nginx 的使用方法及模块
查看>>
alter system switch logfile与alter system archive log current
查看>>
H3C MSR3020路由NQA实例配置
查看>>
数据类型转换的常见错误
查看>>
DBA——表级数据恢复之路(一) 请下载附件查看
查看>>
我的友情链接
查看>>
hello,blog!
查看>>
搭建最简单ceph环境(入门)
查看>>