首页 技术 正文
技术 2022年11月12日
0 收藏 538 点赞 3,335 浏览 2100 个字

CRB and His Birthday

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1112    Accepted Submission(s): 559

Problem DescriptionToday 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
 InputThere 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.
 OutputFor each test case, output the maximum candies she can gain. Sample Input1
100 2
10 2 1
20 1 1 Sample Output21

Hint

CRB’s mom buys 10 presents of first kind, and receives 2 × 10 + 1 = 21 candies.

 AuthorKUT(DPRK) Source2015 Multi-University Training Contest 10题意:买东西,给你N的钱M种类的东西每类东西,如果买就送A*x+B的蜡烛。x为购买数,问最多可以获得多少蜡烛。思路:因为送A*x+B的蜡烛,如果没有后面的常数B,就相当于价值为A,所以直接完全背包就可以解决。但是后面多了个常数B,所以还有考虑买不买的情况,所以01背包先跑一遍,再跑一遍完全背包就可以了。O(M*N);

 1 #include<stdio.h>
2 #include<algorithm>
3 #include<iostream>
4 #include<string.h>
5 #include<math.h>
6 #include<queue>
7 #include<string.h>
8 #include<stack>
9 #include<vector>
10 #include<map>
11 #define sc(x) scanf("%I64d",&x)
12 #define pr(x) printf("%I64d",x)
13 #define prr(x) printf("%I64d\n",x)
14 #define prrr(x) printf(" %I64d",x)
15 #define FOR(i,p,q) for(int i=p;i<=q;i++)
16 typedef struct pp
17 {
18 int x;
19 int y;
20 int z;
21 }ss;
22 ss aa[3000];
23 int dp[3000];
24 using namespace std;
25 int main(void)
26 {
27 int n,i,j,k,p,q;
28 int N,M;
29 scanf("%d",&k);
30 while(k--)
31 {
32 scanf("%d %d",&N,&M);
33 memset(dp,0,sizeof(dp));
34 for(i=1;i<=M;i++)
35 {
36 scanf("%d %d %d",&aa[i].x,&aa[i].y,&aa[i].z);
37 }
38 for(i=1;i<=M;i++)
39 {
40 for(j=N;j>=aa[i].x;j--)
41 {
42 dp[j]=max(dp[j],dp[j-aa[i].x]+aa[i].z+aa[i].y);
43 }
44 }
45 for(i=1;i<=M;i++)
46 {
47 for(j=aa[i].x;j<=N;j++)
48 {
49 dp[j]=max(dp[j],dp[j-aa[i].x]+aa[i].y);
50 }
51 }
52 printf("%d\n",dp[N]);
53 }
54 return 0;
55 }

 

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,997
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,511
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,356
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,139
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,770
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,848