CRB and His Birthday(背包)
CRB and His Birthday
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 357 Accepted Submission(s): 191
Problem Description
Today is CRB’s birthday. His mom decided to buy many presents for her lovely son.
She went to the nearest shop with M Won(currency unit).
At the shop, there are N kinds of presents.
It costs Wi Won to buy one present of i-th kind. (So it costs k × Wi Won to buy k of them.)
But as the counter of the shop is her friend, the counter will give Ai × x + Bi candies if she buys x(x>0) presents of i-th kind.
She wants to receive maximum candies. Your task is to help her.
1 ≤ T ≤ 20
1 ≤ M ≤ 2000
1 ≤ N ≤ 1000
0 ≤ Ai, Bi ≤ 2000
1 ≤ Wi ≤ 2000
Input
There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:
The first line contains two integers M and N.
Then N lines follow, i-th line contains three space separated integers Wi, Ai and Bi.
Output
For each test case, output the maximum candies she can gain.
Sample Input
1
100 2
10 2 1
20 1 1
Sample Output
21
Hint
CRB’s mom buys 10 presents of first kind, and receives 2 × 10 + 1 = 21 candies.
Author
KUT(DPRK)
Source
2015 Multi-University Training Contest 10
题意:今天是CRB的生日,他的妈妈去商店给他买礼物,由于收银员是他妈妈的好朋友,所以收银员会按照不同礼 物的件数x赠与CRB的妈妈(a*x+b)块糖果。CRB的妈妈总共带了w元钱,总共有n种礼物。t组输入,每组先输入w 和n,接下来n行每行是该种礼物需要花费的价格和对应的a与b。求CRB的妈妈最多能获得多少糖果。
思路:因为每件物品都是无穷的所以是完全背包,但是只有在买第一件物品是多加b,所以将物品分成两部分,一部分是只有一件物品,进行01背包,一部分进行完全背包
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <algorithm>
#define INF 0x3f3f3f3f
using namespace std;
typedef unsigned long long LL;
int Dp[2100];
int n,m;
int main()
{
int T;
int w,a,b;
scanf("%d",&T);
while(T--)
{
scanf("%d %d",&m,&n);
memset(Dp,0,sizeof(Dp));
for(int i=1;i<=n;i++)
{
scanf("%d %d %d",&w,&a,&b);
for(int j=m;j>=w;j--)//01背包
{
Dp[j]=max(Dp[j],Dp[j-w]+a+b);
}
for(int j=w;j<=m;j++)//完全背包
{
Dp[j]=max(Dp[j],Dp[j-w]+a);
}
}
printf("%d\n",Dp[m]);
}
return 0;
}
CRB and His Birthday(背包)的更多相关文章
- 2015暑假多校联合---CRB and His Birthday(01背包)
题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=5410 Problem Description Today is CRB's birthda ...
- HDU 5410 CRB and His Birthday(完全背包变形)
CRB and His Birthday Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- hdu 5410 CRB and His Birthday(混合背包)
Problem Description Today is CRB's birthday. His mom decided to buy many presents for her lovely son ...
- HDU 5410 CRB and His Birthday ——(完全背包变形)
对于每个物品,如果购买,价值为A[i]*x+B[i]的背包问题. 先写了一发是WA的= =.代码如下: #include <stdio.h> #include <algorithm& ...
- 混合背包 hdu5410 CRB and His Birthday
传送门:点击打开链接 题意:你有M块钱,如今有N件商品 第i件商品要Wi块,假设你购买x个这种商品.你将得到Ai*x+Bi个糖果 问能得到的最多的糖果数 思路:很好的一道01背包和全然背包结合的题目 ...
- HDU 5410 CRB and His Birthday (01背包,完全背包,混合)
题意:有n种商品,每种商品中有a个糖果,如果买这种商品就送多b个糖果,只有第一次买的时候才送.现在有m元,最多能买多少糖果? 思路:第一次买一种商品时有送糖果,对这一次进行一次01背包,也就是只能买一 ...
- 背包DP HDOJ 5410 CRB and His Birthday
题目传送门 题意:有n个商店,有m金钱,一个商店买x件商品需要x*w[i]的金钱,得到a[i] * x + b[i]件商品(x > 0),问最多能买到多少件商品 01背包+完全背包:首先x == ...
- hdu 5410 CRB and His Birthday 01背包和全然背包
#include<stdio.h> #include<string.h> #include<vector> #include<queue> #inclu ...
- HDU 5410(2015多校10)-CRB and His Birthday(全然背包)
题目地址:HDU 5410 题意:有M元钱,N种礼物,若第i种礼物买x件的话.会有Ai*x+Bi颗糖果,现给出每种礼物的单位价格.Ai值与Bi值.问最多能拿到多少颗糖果. 思路:全然背包问题. dp[ ...
随机推荐
- Troubleshooting JDK
收集整理下JDK自带的关于 Troubleshooting 的文档 Java 2 Platform, Standard Edition 5.0 Troubleshooting and Diagnost ...
- Java数组(初学者必看)
数组无论在哪种编程语言中都算是最重要的数据结构之一,同时不同语言的实现及处理也不尽相同.但凡写过一些程序的人都知道数组的价值及理解数组的重要性,与链表一道,数组成为了基本的数据结构.尽管Java提供了 ...
- 、JAVA-异常
异常 1.种类(error 系统异常,无法处理)(exception 程序异常,可以处理) 1.算数异常 2.空指针异常 原因:对象没有实例化就调用他的实例方法,会造成空指针异常 2.常见异常 1.R ...
- Java基础(52):ClassCastException详解(转)
ClassCastException,从字面上看,是类型转换错误,通常是进行强制类型转换时候出的错误.下面对产生ClassCastException异常的原因进行分析,然后给出这种异常的解决方法. 这 ...
- Server.Transfer,Response.Redirect用法点睛
Server.Transfer,Response.Redirect的区别 如果你读过很多行业杂志和 ASP.NET 示例,你会发现,大多数人使用 Response.Redirect 将用户引导到另一个 ...
- C++之路进阶——codevs1036(商务旅行)
1036 商务旅行 题目描述 Description 某首都城市的商人要经常到各城镇去做生意,他们按自己的路线去做,目的是为了更好的节约时间. 假设有N个城镇,首都编号为1,商人从首都出发,其他各城镇 ...
- 变形--位移 translate()
translate()函数可以将元素向指定的方向移动,类似于position中的relative.或以简单的理解为,使用translate()函数,可以把元素从原来的位置移动,而不影响在X.Y轴上的任 ...
- 1.表单中 get与post提交方法的区别?
get是发送请求HTTP协议通过url参数传递进行接收,而post是实体数据,可以通过表单提交大量信息. get是从服务器上获取数据,post是向服务器传送数据. GET方式提交的数据最多只能有102 ...
- sql server 查看数据库编码格式
user masterselect SERVERPROPERTY(N'edition') as Edition --数据版本,如企业版.开发版等,SERVERPROPERTY(N'collation' ...
- 夺命雷公狗—angularjs—3—表单验证的高级用法
其实我们的angularjs都是是块状代码,其实是可以在实际开发中保存下来以后就可以达到重复利用的目的了.. 废话不多说,直接上代码: <!doctype html> <html l ...