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(背包)的更多相关文章

  1. 2015暑假多校联合---CRB and His Birthday(01背包)

    题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=5410 Problem Description Today is CRB's birthda ...

  2. HDU 5410 CRB and His Birthday(完全背包变形)

    CRB and His Birthday Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  3. hdu 5410 CRB and His Birthday(混合背包)

    Problem Description Today is CRB's birthday. His mom decided to buy many presents for her lovely son ...

  4. HDU 5410 CRB and His Birthday ——(完全背包变形)

    对于每个物品,如果购买,价值为A[i]*x+B[i]的背包问题. 先写了一发是WA的= =.代码如下: #include <stdio.h> #include <algorithm& ...

  5. 混合背包 hdu5410 CRB and His Birthday

    传送门:点击打开链接 题意:你有M块钱,如今有N件商品 第i件商品要Wi块,假设你购买x个这种商品.你将得到Ai*x+Bi个糖果 问能得到的最多的糖果数 思路:很好的一道01背包和全然背包结合的题目 ...

  6. HDU 5410 CRB and His Birthday (01背包,完全背包,混合)

    题意:有n种商品,每种商品中有a个糖果,如果买这种商品就送多b个糖果,只有第一次买的时候才送.现在有m元,最多能买多少糖果? 思路:第一次买一种商品时有送糖果,对这一次进行一次01背包,也就是只能买一 ...

  7. 背包DP HDOJ 5410 CRB and His Birthday

    题目传送门 题意:有n个商店,有m金钱,一个商店买x件商品需要x*w[i]的金钱,得到a[i] * x + b[i]件商品(x > 0),问最多能买到多少件商品 01背包+完全背包:首先x == ...

  8. hdu 5410 CRB and His Birthday 01背包和全然背包

    #include<stdio.h> #include<string.h> #include<vector> #include<queue> #inclu ...

  9. HDU 5410(2015多校10)-CRB and His Birthday(全然背包)

    题目地址:HDU 5410 题意:有M元钱,N种礼物,若第i种礼物买x件的话.会有Ai*x+Bi颗糖果,现给出每种礼物的单位价格.Ai值与Bi值.问最多能拿到多少颗糖果. 思路:全然背包问题. dp[ ...

随机推荐

  1. 自动备份sqlexpress 数据库脚本

    Create PROCEDURE [dbo].[usp_BackupDatabase] @databaseName sysname,@backupPath nvarchar(255), @backup ...

  2. Leetcode: Range Sum Query - Mutable && Summary: Segment Tree

    Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...

  3. Lintcode: Singleton && Summary: Synchronization and OOD

    Singleton is a most widely used design pattern. If a class has and only has one instance at every mo ...

  4. ligerUI_入门_001_设置文本能否被编辑、事件

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. [div+css]网站布局实例二

    重点: 合理应用"xhtml标签"建立良好的页面结构 拿到一份"设计方案"的效果图后不要立即开始编码,而是要 首先理清"各元素之间的关系"; ...

  6. Debian类系统必做——将【你的用户】加入sudoers用户组

    切换到root:su root   修改sudoers nano /etc/sudoers 在root    ALL=(ALL:ALL) ALL下,加入:liz        ALL=(ALL:ALL ...

  7. 我的代码观——关于ACM编程风格与librazy网友的对话

    序 在拙文 <高手看了,感觉惨不忍睹——关于“[ACM]杭电ACM题一直WA求高手看看代码”>中,我对ACMer们的一些代码“惯例”发表了我的看法, librazy网友在评论中给出了他的一 ...

  8. Fury观后感

    刚看完,淋雨汽车回来的,电影很精彩.前期略慢热(我还去了躺厕所),军人的黑色幽默,冷酷的军旅生活作为基调.内容我就不ao述了,新兵蛋诺曼的经历是这部电影的为主线(也有人说诺曼是观众的代入点,准确来说他 ...

  9. SQL 基础语法(创建表空间、用户、并授予权限、数据的增删改查) --(学习笔记)[转]

    --创建表空间 名:lyayzh_test create tablespace lyayzh_test --创建表数据文件 名:lyayzh_test_data.dbf 必须以dbf为后缀 dataf ...

  10. ActiveMQ消息的可靠性机制(转)

    文章转自:http://www.linuxidc.com/Linux/2013-02/79664.htm 1.JMS消息确认机制 JMS消息只有在被确认之后,才认为已经被成功地消费了.消息的成功消费通 ...