题目链接

http://acm.split.hdu.edu.cn/showproblem.php?pid=5410

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
 
Recommend
wange2014
 
题意:输入M,N,分别表示总的钱数和物品种数,接下来输入N行,每行3个数,单价、买一件送的糖数 、买一次送的糖数   求最多能得到多少糖?
 
思路:01背包,dp[i]表示i钱下能得到最多的糖数,vis[i][j]表示i钱下得到最多糖时,是否买j物品,状态转移方程dp[i]=dp[i-kind[j][0]]+kind[j][1]+(vis[i-kind[j][0]][j]==0) * kind[j][2];
 
代码如下:
 
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#define eps 1e-8
#define maxn 105
#define inf 0x3f3f3f3f3f3f3f3f
#define IN freopen("in.txt","r",stdin);
using namespace std;
int dp[];
int vis[][];
int kind[][]; int main()
{
int T;
int M,N;
cin>>T;
while(T--)
{
scanf("%d%d",&M,&N);
for(int i=;i<N;i++)
scanf("%d%d%d",&kind[i][],&kind[i][],&kind[i][]);
memset(dp,,sizeof(dp));
memset(vis,,sizeof(vis)); for(int i=;i<=M;i++)
{
int flag=-;
for(int j=;j<N;j++)
{
if(i<kind[j][]) continue;
int s=dp[i-kind[j][]]+kind[j][];
if(!vis[i-kind[j][]][j]) s+=kind[j][];
if(dp[i]<s)
{
dp[i]=s;
flag=j;
}
}
if(flag>=)
{
for(int j=;j<N;j++)
{
vis[i][j]=vis[i-kind[flag][]][j];
}
vis[i][flag]++;
}
}
int tmp=;
for(int i=;i<=M;i++)
tmp=max(tmp,dp[i]);
printf("%d\n",tmp);
}
return ;
}

2015暑假多校联合---CRB and His Birthday(01背包)的更多相关文章

  1. 2015暑假多校联合---Zero Escape(变化的01背包)

    题目链接 http://acm.hust.edu.cn/vjudge/contest/130883#problem/C Problem Description Zero Escape, is a vi ...

  2. 2015暑假多校联合---Expression(区间DP)

    题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=5396 Problem Description Teacher Mai has n numb ...

  3. 2015暑假多校联合---Mahjong tree(树上DP 、深搜)

    题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=5379 Problem Description Little sun is an artis ...

  4. 2015暑假多校联合---Cake(深搜)

    题目链接:HDU 5355 http://acm.split.hdu.edu.cn/showproblem.php?pid=5355 Problem Description There are m s ...

  5. 2015暑假多校联合---Friends(dfs枚举)

    原题链接 Problem Description There are n people and m pairs of friends. For every pair of friends, they ...

  6. 2015暑假多校联合---Assignment(优先队列)

    原题链接 Problem Description Tom owns a company and he is the boss. There are n staffs which are numbere ...

  7. 2015暑假多校联合---Problem Killer(暴力)

    原题链接 Problem Description You are a "Problem Killer", you want to solve many problems. Now ...

  8. 2016暑假多校联合---Rikka with Sequence (线段树)

    2016暑假多校联合---Rikka with Sequence (线段树) Problem Description As we know, Rikka is poor at math. Yuta i ...

  9. 2016暑假多校联合---Windows 10

    2016暑假多校联合---Windows 10(HDU:5802) Problem Description Long long ago, there was an old monk living on ...

随机推荐

  1. Js~对数组进行分组户数

    在sql里有group by,主要对数据结果集进行分组统计,而对于JS来说,有时我们也需要这种功能,例如一个数据{"dog","cat","dog&q ...

  2. 手把手教你在VirtualBox中与主机共享文件夹

    安装VirtualBox为了共享文件夹,折腾了一晚上!网上的很多资料都不是很全面,这里就全面的总结一下,如果有其他的疑问,可以留言多多交流. VirtualBox下载地址,版本为5.1.2 设置共享文 ...

  3. Atitit  五种IO模型attilax总结 blocking和non-blocking synchronous IO和asynchronous I

    Atitit  五种IO模型attilax总结 blocking和non-blocking synchronous IO和asynchronous I   1.1. .3 进程的阻塞1 1.2. 网络 ...

  4. Visual Studio 2015 Bowser Link的功能不停的向服务端发送请求

    Visual Studio 2015新建的mvc项目 默认在每个视图上生成一些JavaScript脚本

  5. javaweb回顾第十篇JSTL

    前言:JSTL(JSP Standard Tag Library)JSP标准标签库.它的目的是为了简化JSP的开发,如何没有JSTL可能我们开发的时候就需要写大量的自定义标签,无疑会加大开发难度,有了 ...

  6. iOS9和Xcode7

    2015.06.08苹果放出了iOS9以及Xcode7的 Beta测试版本.有一句话非常引入注意: https://developer.apple.com/xcode/ Now everyone ca ...

  7. 【WP 8.1开发】推送通知测试服务端程序

    所谓推送通知,用老爷爷都能听懂的话说,就是: 1.我的服务器将通知内容发送到微软的通知服务器,再由通知服务器帮我转发消息. 2.那么,微软的推送服务器是如何知道我的服务器要发消息给哪台手机呢?手机客户 ...

  8. Windows Azure HandBook (5) Azure混合云解决方案

    <Windows Azure Platform 系列文章目录> 在很多情况下,我们都会遇到本地私有云和公有云做互通互联的混合云场景.对于这种混合云的场景,微软的Windows Azure会 ...

  9. SQL Server存储(6/8) :理解DCM页

    我们已经讨论了各种不同的页,包括数据页.GAM与SGAM页.PFS页,还有IAM页.今天我们来看下差异变更页(Differential Change Map:DCM ),还有差异备份(differen ...

  10. iOS平台快速发布HT for Web拓扑图应用

    iOS平台一直是封闭的生态圈,iOS开发者要缴纳年费加入开发者计划才可进行iOS平台的APP开发测试,所开发的APP需要上传到App Store经过苹果审核以后才可对外发布.如果要开发企业内部应用,则 ...