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. PostgreSQL Replication之第九章 与pgpool一起工作(6)

    9.6 运行pgpool和流复制 pgpool也可以和除了语句级别的复制之外的流复制一起使用.一个完美的方案是使用PostgreSQL的板载复制和仅仅使用pgpool的负载均衡与连接池. 实际上,这样 ...

  2. 点的双联通+二分图的判定(poj2942)

    Knights of the Round Table Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 10804   Acce ...

  3. URAL 1146 Maximum Sum(DP)

    Given a 2-dimensional array of positive and negative integers, find the sub-rectangle with the large ...

  4. springday02-go4

    1.复制xml到container/annotation下2.新建Waiter类,构造函数,初始化以及销毁函数3.在Waiter方法体前面加上@Component4.xml中添加组件扫描代码5.tes ...

  5. paper 50 :人脸识别简史与近期进展

    自动人脸识别的经典流程分为三个步骤:人脸检测.面部特征点定位(又称Face Alignment人脸对齐).特征提取与分类器设计.一般而言,狭义的人脸识别指的是"特征提取+分类器"两 ...

  6. react编译器jsxTransformer,babel

    1.JSX是什么JSX其实是JavaScript的扩展,React为了代码的可读性更方便地创建虚拟DOM等原因,加入了一些类似XML的语法的扩展. 2.编译器——jsxTransformerJSX代码 ...

  7. logstash中的redis插件

    redis作为logstash中的官方broker,既有input插件,还有output插件. redis input插件 data_type属性: 有三种类型, list -> BLPOP - ...

  8. mysql设置时区方法

    set global time_zone = '+2:00'; ##修改mysql全局时区 set time_zone = '+2:00'; ##修改当前会话时区 flush privileges; ...

  9. oracle中的常用函数

    一.运算符算术运算符:+ - * / 可以在select 语句中使用连接运算符:|| select deptno|| dname from dept; 比较运算符:> >= = != &l ...

  10. 夺命雷公狗—angularjs—4—继承和修正继承

    angularjs 中也有继承的方法,废话不多说,看代码: <!doctype html> <html lang="en"> <head> &l ...