sdut2408 Pick apples
来源:互联网 发布:热玛吉效果怎么样知乎 编辑:程序博客网 时间:2024/06/12 20:33
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 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.
输入
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
提示
来源
#include<iostream>#include<cstdio>#include<cstring>using namespace std;long long V,dp[20100],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 <= 10000){ for(int i=0; i<3; i++) CompletePack(s[i], p[i]); cout<<dp[V]<<endl; }else{ long long ans = (V-10000) / s[id]*p[id]; V = V - (V - 10000) / s[id] * s[id]; for(int i=0; i<3; i++) CompletePack(s[i], p[i]); cout << dp[V] + ans <<endl; } } return 0;}
- sdut2408 Pick apples
- sdut2408 Pick apples(山东第三届省赛)
- sdut2408 pick apples (贪心+背包)山东省第三届ACM省赛
- Pick apples
- Pick Apples
- Pick apples
- SDUT 2408 Pick apples
- SDUT 2408 Pick apples
- SDUT 2408:Pick apples
- SDUT:2408 Pick apples(贪心+完全背包)
- HDUT-2408-Pick apples(贪心+背包)
- 第三届山东ACM Pick apples
- 山东省第三届ACM省赛 Pick apples
- Pick apples(动态规划,难点背包容量太大)
- 第三届ACM山东省赛 Pick apples [贪心+动规]
- SDUT 2408 Pick apples 贪心+背包(大容量背包)
- 2013山东省第三届ACM省赛 Pick apples
- Pick apples(山东省第三届ACM大学生程序设计竞赛)
- 为啥我的程序超时?随便谈谈时间复杂度
- Spring MVC
- 注册表被修改的常见问题
- 第八周程序设计课解题报告
- struts2 package 属性说明
- sdut2408 Pick apples
- LeetCode Nth Highest Salary
- 第八周的药之程序风格
- ZOJ 3866 Cylinder Candy
- HDU 4089 Activation 概率dp
- Hibernate之CRUD工具类
- C++中一种十分有用的容器vector
- 第九周期末(中)考试解题报告
- 二分查找之k小数