CRB and His Birthday(hdu 5410)
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
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
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.
100 2
10 2 1
20 1 1
CRB's mom buys 10 presents of first kind, and receives 2 × 10 + 1 = 21 candies.
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 }
CRB and His Birthday(hdu 5410)的更多相关文章
- HDU 5410(2015多校10)-CRB and His Birthday(全然背包)
题目地址:HDU 5410 题意:有M元钱,N种礼物,若第i种礼物买x件的话.会有Ai*x+Bi颗糖果,现给出每种礼物的单位价格.Ai值与Bi值.问最多能拿到多少颗糖果. 思路:全然背包问题. dp[ ...
- HDU 5410 CRB and His Birthday(完全背包变形)
CRB and His Birthday Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- hdu 5410 CRB and His Birthday(混合背包)
Problem Description Today is CRB's birthday. His mom decided to buy many presents for her lovely son ...
- HDU 5410 CRB and His Birthday ——(完全背包变形)
对于每个物品,如果购买,价值为A[i]*x+B[i]的背包问题. 先写了一发是WA的= =.代码如下: #include <stdio.h> #include <algorithm& ...
- HDU 5410 CRB and His Birthday
题目大意: 一个人要去买礼物,有M元.有N种礼物,每件礼物的价值是Wi, 你第i件礼物买k个 是可以得到 Ai * k + Bi 个糖果的. 问怎么才能使得你得到的糖果数目最多. 其实就是完全背包 ...
- HDU 5410 CRB and His Birthday (01背包,完全背包,混合)
题意:有n种商品,每种商品中有a个糖果,如果买这种商品就送多b个糖果,只有第一次买的时候才送.现在有m元,最多能买多少糖果? 思路:第一次买一种商品时有送糖果,对这一次进行一次01背包,也就是只能买一 ...
- hdu 5410 CRB and His Birthday 01背包和全然背包
#include<stdio.h> #include<string.h> #include<vector> #include<queue> #inclu ...
- HDU 5416 CRB and Tree(前缀思想+DFS)
CRB and Tree Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tot ...
- hdu 5412 CRB and Queries
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5412 CRB and Queries Description There are $N$ boys i ...
随机推荐
- Flink(六)【ParameterTool类】
ParameterTool 工具类 object ParameterToolTest { def main(args: Array[String]): Unit = { val params: Par ...
- Spark(六)【RDD的血缘依赖】
RDD依赖关系 1. RDD血缘关系 RDD只支持粗粒度转换,即在大量记录上执行的单个操作.将创建RDD的一系列Lineage(血统)记录下来,以便恢复丢失的分区.RDD的Lineage会记录RD ...
- redis入门到精通系列(四):Jedis--使用java操作redis详解
(一)前言 如果不把数据库和后端语言联系起来,就起不到数据库应该要起到的作用.Java语言通过JDBC操作mysql,用Jedis操作redis.当然了,java操作redis的方式不止jedis一种 ...
- clickhouse安装数据导入及查询测试
官网 https://clickhouse.tech/ quick start ubantu wget https://repo.yandex.ru/clickhouse/deb/lts/main/c ...
- vue中vuex的五个属性和基本用法
VueX 是一个专门为 Vue.js 应用设计的状态管理构架,统一管理和维护各个vue组件的可变化状态(你可以理解成 vue 组件里的某些 data ). Vuex有五个核心概念: state, ge ...
- spring生成EntityManagerFactory的三种方式
spring生成EntityManagerFactory的三种方式 1.LocalEntityManagerFactoryBean只是简单环境中使用.它使用JPA PersistenceProvide ...
- 【Linux】【Services】【SaaS】Docker+kubernetes(12. 部署prometheus/grafana/Influxdb实现监控)
1.简介 1.1. 官方网站: promethos:https://prometheus.io/ grafana:https://grafana.com/ 1.2. 架构图 2. 环境 2.1. 机器 ...
- [笔记] Informer: Beyond Efficient Transformer for Long Sequence Time-Series Forecasting
原文地址:https://arxiv.org/abs/2012.07436 源码地址:https://github.com/zhouhaoyi/Informer2020
- Linux服务加入systemctl|service管理
一.加入systemctl 1.添加 vim /usr/lib/systemd/system/user_timejob.service # copy to /usr/lib/systemd/syste ...
- Tableau如何使用 度量值和度量名称
一.把子类别拖拽至列 二.度量值拖拽至行 三.度量名称拖拽至筛选器,右键-编辑筛选器-选择销售额和利润 四.度量名称拖拽是标记选择颜色-其它细节调整-最终结果如下所示