Pick apples(山东省第三届ACM程序设计大赛 贪心+背包)
来源:互联网 发布:ecshop app源码 编辑:程序博客网 时间:2024/05/17 09:39
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.
Sample Input
1
1 1
2 1
3 1
6
Sample Output
Case 1: 6
大范围贪心,小范围背包。
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int MAX_BACK=1e6;//背包的范围typedef long long int LL;LL dp[MAX_BACK*2+50];typedef struct node{ int siz; int pri; double aver;} nod;nod s[10];bool cmp(nod p,nod q){ return p.aver>q.aver;}void comback(LL V){ memset(dp,0,sizeof(dp)); for(int i=0; i<3; i++) { for(int j=s[i].siz; j<=V; j++) dp[j]=max(dp[j],dp[j-s[i].siz]+s[i].pri); }}int main(){ int T; int CASE=1; scanf("%d",&T); while(T--) { LL ans=0; for(int i=0; i<3; i++) { scanf("%d%d",&s[i].siz,&s[i].pri); s[i].aver=1.0*s[i].pri/s[i].siz; } LL V; scanf("%lld",&V); if(V<=MAX_BACK) { comback(V); cout<<"Case "<<CASE++<<": "<<dp[V]<<endl; } else { sort(s,s+3,cmp); LL x=V-MAX_BACK; ans=ans+(x/s[0].siz*s[0].pri); LL mod=x%s[0].siz; comback(MAX_BACK+mod); cout<<"Case "<<CASE++<<": "<<ans+dp[MAX_BACK+mod]<<endl; } }}
- Pick apples(山东省第三届ACM程序设计大赛 贪心+背包)
- SDUT 2408 Pick apples(完全背包+贪心)2012年"浪潮杯"山东省第三届ACM大学生程序设计竞赛
- sdut2408 pick apples (贪心+背包)山东省第三届ACM省赛
- Pick apples(山东省第三届ACM大学生程序设计竞赛)
- 第三届ACM山东省赛 Pick apples [贪心+动规]
- 山东省第三届ACM省赛 Pick apples
- 2013山东省第三届ACM省赛 Pick apples
- HDUT-2408-Pick apples(贪心+背包)
- 第三届山东ACM Pick apples
- [2012山东ACM省赛] Pick apples (贪心,完全背包,枚举)
- SDUT 2408 Pick apples 贪心+背包(大容量背包)
- 山东省第三届ACM大学生程序设计竞赛 Fruit Ninja I(01背包)
- 山东省第一届ACM程序设计大赛 Balloons (简单dfs)
- SDUT:2408 Pick apples(贪心+完全背包)
- 山东省第三届ACM大学生程序设计竞赛(待添加)
- Greatest Number 山东省第一届ACM程序设计大赛
- 退役赛总结(山东省第八届ACM程序设计大赛总结)
- 河南省第三届ACM程序设计大赛题解
- anacoda 安装tensorflow
- el表达式
- 【正一专栏】谁能阻止超神的曼城
- 加油吧!数字化转型@有了桌面云,再也不愁我的英语学习了
- 拿什么奉献给你,“一带一路”2.0时代!
- Pick apples(山东省第三届ACM程序设计大赛 贪心+背包)
- 《深入分布式缓存:从原理到实践》
- 开发人员学Linux(13):CentOS7安装配置IT设备监控系统Zabbix
- spring boot 配置说明
- Java集合框架:ArrayList
- SQLServer 利用profiler生成脚本在后台跟踪堵塞语句或慢查询语句
- Canvas 入门2 圆、矩形、路径、贝塞尔曲线、Path2D
- angular的hero例子(4)
- 程序员快速记忆英文单词的专属诀窍