SDUT 2408:Pick apples
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<stdio.h>
#define max(a,b) (a>b?a:b)
int s[4],p[4],kk=1;
long long dp[4][1000005];
long long dpp(int v)
{
for(int i=1; i<=3; ++i)
for(int j=0; j<=v; ++j)
{
if(j>=s[i])dp[i][j]=max(dp[i-1][j],dp[i][j-s[i]]+p[i]);
else dp[i][j]=dp[i-1][j];
}
return dp[3][v];
}
int main()
{
int t;
scanf( "%d",&t );
while( t-- )
{
int maxx=0,v,g=1;
for(int i=1; i<=3; i++)
{
scanf("%d%d",&s[i],&p[i]);
g*=s[i];
}
scanf("%d",&v);
for(int i=1; i<=3; ++i)
maxx=maxx>g/s[i]*p[i]?maxx:g/s[i]*p[i];
long long ans=(long long)(v/g)*maxx;
v%=g;
ans+=dpp(v);
printf("Case %d: %lld\n",kk++,ans);
}
return 0;
}
SDUT 2408:Pick apples的更多相关文章
- [2012山东ACM省赛] Pick apples (贪心,完全背包,枚举)
Pick apples Time Limit: 1000MS Memory limit: 165536K 题目描述 Once ago, there is a mystery yard which on ...
- Pick apples(大范围贪心,小范围完全背包)
Pick apples Time Limit: 1000MS Memory Limit: 165536KB Submit Statistic Discuss Problem Description O ...
- [2012山东ACM省赛] Pick apples (贪心,全然背包,枚举)
Pick apples Time Limit: 1000MS Memory limit: 165536K 题目描写叙述 Once ago, there is a mystery yard which ...
- 10年省赛-Greatest Number (二分+暴力) + 12年省赛-Pick apples(DP) + UVA 12325(暴力-2次枚举)
题意:给你n个数,在里面取4个数,可以重复取数,使和不超过M,求能得到的最大的数是多少: 思路:比赛时,和之前的一个题目很像,一直以为是体积为4(最多选择四次)的完全背包,结果并不是,两两求和,然后二 ...
- sdut2408 pick apples (贪心+背包)山东省第三届ACM省赛
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/svitter/article/details/24642587 本文出自:http://blog.c ...
- 山东省第三届ACM省赛
Solved ID PID Title Accepted Submit A 2407 Impasse (+) 0 0 B 2415 Chess 0 0 C 2414 An interest ...
- hdu5303Delicious Apples
题意大概就是有n框苹果放在长度为L的环上,每框有ai个苹果.你有一个容量为k的框.要你从0点处出发,随意走.框满了就回到0点把苹果放在那里.继续走直到把苹果都拿完为止.问你最少要走多少路程. 首先贪心 ...
- hdu多校第4场 B Harvest of Apples(莫队)
Problem B. Harvest of Apples Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Su ...
- Problem B. Harvest of Apples HDU - 6333(莫队)
Problem Description There are n apples on a tree, numbered from 1 to n.Count the number of ways to p ...
随机推荐
- iOS 事件穿透
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typica ...
- ASP.NET在IE9,IE10,IE11中Form表单身份验证失效问题解决方法
已经研究出解决方案. IE9:在web.config中的forms中增加name=".xCookie"属性即可. IE10或IE11: 在web.config中的forms中增加c ...
- JavaBean 动作元素事例
JavaBean.jsp JavaBeanSuccess.jsp Type类 效果
- 算法训练 Torry的困惑(基本型)
http://lx.lanqiao.org/problem.page?gpid=T129 算法训练 Torry的困惑(基本型) 时间限制:1.0s 内存限制:512.0MB 问题描述 ...
- Ubuntu Firefox installs Flashplayer
Adobe flash 下载(https://get.adobe.com/flashplayer/) tar.gz版本(注:adobe 提供了yum,rpm,tar.gz和APT四种版本,yum和t ...
- 数据库SQL CRUD
1.删除表 drop table +表名 2.修改表 alter table+表名+ add(添加)+列名+ int(类型) alter table+表名+ drop(删除)+column(列) ...
- ajax和servlet交互,表单日历插件,表单验证,form.js
我的index.jsp <body> <a>点我获取数据</a> <table border=1px> <tr> <td>ID& ...
- 开源日志技术log4j
老师的总结: 日志:除了能记录异常信息,还可以记录程序正常运行时的关键信息. 使用log4j来进行日志文件记录经典步骤: 001.在项目中创建一个lib文件夹,然后将下载好的jar包copy到该文件夹 ...
- input type=file 标签禁止让用户手动输入
常规的Web应用程序中涉及到文件上传的部分都不可避免地会使用到<input type="file"/>控件,在上传文件的时候通过点击“浏览”按钮,在弹出的文件选择对话框 ...
- oracle的散列聚簇表
在簇表中,Oracle使用存储在索引中的键值来定位表中的行, 而在散列聚簇表中,使用了散列函数代替了簇索引,先通过内部函数或者自定义的函数进行散列计算,然后再将计算得到的码值用于定位表中的行. 创建散 ...