2015多校联合第十场hdu5410CRB and His Birthday 01背包+完全背包
来源:互联网 发布:设置铃声的软件 编辑:程序博客网 时间:2024/05/22 06:35
Problem Description
Today is CRB's birthday. His mom decided to buy many presents for her lovely son.
She went to the nearest shop withM Won(currency unit).
At the shop, there areN kinds of presents.
It costsWi 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 giveAi × 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
She went to the nearest shop with
At the shop, there are
It costs
But as the counter of the shop is her friend, the counter will give
She wants to receive maximum candies. Your task is to help her.
1 ≤
1 ≤
1 ≤
0 ≤
1 ≤
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 integersM and N .
ThenN lines follow, i -th line contains three space separated integers Wi , Ai and Bi .
The first line contains two integers
Then
Output
For each test case, output the maximum candies she can gain.
Sample Input
1100 210 2 120 1 1
Sample Output
21HintCRB's mom buys 10 presents of first kind, and receives 2 × 10 + 1 = 21 candies.
第一次搜多校赛的题解,好在于看题解明白了啊啊啊,好激动,而且背着敲1A!!多久没有了这种感觉了T^T
说正经的-->_--> 这题啥意思 ?完全背包中若选择某种物品,另加b[i]的价值,只加一次
开始百思不得其姐啊啊啊,怎么记录某种物品买没买啊??再加数组太麻烦,把自己绕糊涂了orz
后来题解说先进行一次01背包再进行一次多重背包 茅塞顿开啊啊啊啊
01那次加b[i] 多重背包加只a[i] 01就相当于第一次取某种物品 多重背包 理论知识详见我上一篇博客
刚刚想到会不会两个for重复矛盾了了呢?不不不 装第一个的时候 下面完全背包的总价值一定比01背包的小 Hhhhhh
贴上我光辉的代码 怪不得过的人那么多 看了题解谁都会-->_-->
#include <iostream>#include<cstring>#include<cstdio>using namespace std;int dp[2005],cost[2005],a[2005],b[2005];int main(){ //freopen("cin.txt","r",stdin); int t,m,n; while(cin>>t) { while(t--) { cin>>m>>n; memset(dp,0,sizeof(dp)); for(int i=0;i<n;i++) cin>>cost[i]>>a[i]>>b[i]; for(int i=0;i<n;i++) { for(int j=m;j>=cost[i];j--) if(dp[j]<dp[j-cost[i]]+a[i]+b[i]) dp[j]=dp[j-cost[i]]+a[i]+b[i]; for(int j=cost[i];j<=m;j++) if(dp[j]<dp[j-cost[i]]+a[i]) dp[j]=dp[j-cost[i]]+a[i]; } cout<<dp[m]<<endl; } } return 0;}
0 0
- 2015多校联合第十场hdu5410CRB and His Birthday 01背包+完全背包
- hdu5410CRB and His Birthday 多重背包
- hdu 5410 CRB and His Birthday(01背包+完全背包)
- hdoj5410CRB and His Birthday【01背包+完全背包】
- HDU 5410 CRB and His Birthday (01背包+完全背包)
- hdu5410~CRB and His Birthday(01背包+完全背包)
- hdu 5410 CRB and His Birthday(01背包+完全背包)
- HDU 5410 CRB and His Birthday(完全背包,01背包)
- [HDU 5410]CRB and His Birthday[01、完全背包]
- hdu 5410 CRB and His Birthday 01完全混合背包
- HDU 5410 CRB and His Birthday 混合背包(01背包和完全背包混合)
- HDU 5410 CRB and His Birthday(完全背包)——多校练习10
- hdu 5410 CRB and His Birthday 01背包和完全背包
- HDU 5410 CRB and His Birthday(01背包+完全背包)
- HDU 5410 CRB and His Birthday(完全背包+01背包)
- HDU 5410 CRB and His Birthday(01背包+完全背包)
- HDU-5410-CRB and His Birthday(01背包+完全背包 better)
- HDU 5410 CRB and His Birthday(01背包+完全背包)
- 【Linux系统编程】文件IO操作
- 【LeetCode】(66)Plus One (Easy)
- GDOI2016模拟8.21总结
- poj2253
- Bootstrap 字体图标,下拉列表组件的使用
- 2015多校联合第十场hdu5410CRB and His Birthday 01背包+完全背包
- 有关eigen库在qt中的使用
- JAVA泛型
- 网页源码保存为文件
- CodeForces 题目191C. Fools and Roads(Link Cut Tree,边权加求边权值)
- 【Android开发经验】超好用的json解析工具——Gson项目使用详解
- AX 2009 删除已经发出领料单的订单行
- 华为OJ(MP3光标移动)
- 经典任务调度算法的模拟程序