Pick apples
来源:互联网 发布:nginx 静态文件服务器 编辑:程序博客网 时间:2024/05/17 18:04
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.
示例输入
1 1
1 2
1 3
1 6
示例输出
Case 1: 6
题意:
#include<iostream>#include<cstdio>#include<bits/stdc++.h>using namespace std;const int lmc=1000000;struct node{ int p,m; int pri;}pon[3];long long dp[2*lmc+1],v;bool pma(node a,node b){ a.pri>a.pri;}void work(){ for(int i=0;i<3;i++) { for(int j=pon[i].m;j<=v;j++) { dp[j]=max(dp[j],dp[j-pon[i].m]+pon[i].p); } }}int main(){ int t; scanf("%d",&t); int c=1; while(t--) { memset(dp,0,sizeof(dp)); for(int i=0;i<3;i++) { scanf("%d %d",&pon[i].m,&pon[i].p); pon[i].pri=pon[i].m*1.0/pon[i].p; } scanf("%d",&v); if(v<lmc) { work(); printf("Case %d:%d\n",c++,dp[v]); } else { sort(pon,pon+3,pma); v=v-lmc; long long ans=0; ans=ans+v/pon[0].m*pon[0].p; v=lmc+v-v/pon[0].m*pon[0].m; work(); printf("Case %d:%d\n",c++,dp[v]+ans); } } return 0;}
- Pick apples
- Pick Apples
- Pick apples
- SDUT 2408 Pick apples
- SDUT 2408 Pick apples
- sdut2408 Pick apples
- SDUT 2408:Pick apples
- sdut2408 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大学生程序设计竞赛)
- [2012山东ACM省赛] Pick apples (贪心,完全背包,枚举)
- Volley NetworkImageView setImageResource 不起作用 原因
- 背包问题 初始化
- vue开发公共模块封装(http)
- Java学习笔记—注解(Annotation)的用法
- PHP的4种常见运行模式
- Pick apples
- 【离散化】【转载】
- 终于等来面试,但要注意这四个信号!
- UIView子类初始化的隐藏知识
- Android Support V4,V7,V13的区别
- 0816
- 点亮第一个发光二极管
- Nginx解决Js跨域请求
- String,StringBuffer,StringBuilder之间的区别