HDUT-2408-Pick apples(贪心+背包)
2016-05-03 10:42
423 查看
Pick apples
Time Limit: 1000ms Memory limit: 165536K 有疑问?点这里^_^
题目描述
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 kindof 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.
输入
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.
输出
For each case, first output the case number then follow the most profits she can gain.示例输入
11 12 13 16
示例输出
Case 1: 6
提示
来源
2012年"浪潮杯"山东省第三届ACM大学生程序设计竞赛思路:大范围贪心,小范围背包。
只有三个物品,V=1e8, max(v)=100,可以贪心的取最大性价比到可背包范围,在进行背包。
#include<iostream> #include<cstdio> #include<cstring> using namespace std; long long V,dp[2010],s[5],p[5]; void CompletePack(long long ss,long long pp) { for(long long i=ss; i<=V; i++) if(dp[i]<dp[i-ss]+pp) dp[i]=dp[i-ss]+pp; } int main() { int T,cases=0; scanf("%d",&T); while(T--) { double val,max=0; int id; for(int i=0; i<3; i++) { cin>>s[i]>>p[i]; val=1.0*p[i]/s[i]; if(max<val) { max=val; id=i; } } cin>>V; memset(dp,0,sizeof(dp)); cout<<"Case "<<++cases<<": "; if(V<=500) { for(int i=0; i<3; i++) CompletePack(s[i],p[i]); cout<<dp[V]<<endl; } else { long long ans=(V-500)/s[id]*p[id]; V=V-(V-500)/s[id]*s[id]; for(int i=0; i<3; i++) CompletePack(s[i],p[i]); cout<<dp[V]+ans<<endl; } } return 0; }
相关文章推荐
- iOS中视频播放的学习
- 《Motion Design for iOS》(九)
- Android Fragment中使用Intent组件拍照
- Android中View绘制流程以及invalidate()等相关方法分析
- When Documents Become Databases – Tabulizer R Wrapper for Tabula PDF Table Extractor
- Android service工具类,判断服务是否在运行
- iOS开发中 AVPlayer 深入浅出
- 基于mac,使用android studio进行ndk开发(1)
- android service 本地 远程 总结
- Android开发之滑动图片轮播标题焦点
- android 支持的语言列表(汇总)
- Android学习笔记(一)——Activity基础知识
- Swift—属性观察者-备
- Android WebView顶部进度条
- Android webView 支持缩放及自适应屏幕
- App Xutil框架
- Activity的几种状态
- Android HashMap增强版SoftMap,使用软引用
- Swift—计算属性-备
- Android Studio运行直接打签名包(release)