Sample Input
1
100 2
10 2 1
20 1 1
 
Sample Output
21

题意:共有m元钱和n种东西,求每种单价p,而且你买x个该种物品可以得到Ax+B个,求m元钱最多能得到多少。

思路:先01背包处理出A+B的情况,再用完全背包往里算加A能得到的情况。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
#define maxn 200050 int T,n,m,t,k,l,tot,j;
int q[1005][3];
int dp[2005]; int main()
{
int k,n;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&k,&n);
for(int i = 1;i <= n;i++)
scanf("%d%d%d",&q[i][0],&q[i][1],&q[i][2]);
int maxx = 0;
memset(dp,0,sizeof(dp));
for(int i = 1;i <= n;i++)
for(int j = k;j >= q[i][0];j--)
{
dp[j] = max(dp[j],dp[j-q[i][0]]+ q[i][1] + q[i][2]);
maxx = max(maxx,dp[j]);
} for(int i = 1;i <= n;i++)
for(int j = q[i][0];j <= k;j++)
{
dp[j] = max(dp[j],dp[j-q[i][0]]+ q[i][1]);
maxx = max(maxx,dp[j]);
} printf("%d\n",maxx);
}
return 0;
}

  

2015 多校联赛 ——HDU5410(dp)的更多相关文章

  1. 2015 多校联赛 ——HDU5389(dp)

    Sample Input 4 3 9 1 1 2 6 3 9 1 2 3 3 5 2 3 1 1 1 1 1 9 9 9 1 2 3 4 5 6 7 8 9   Sample Output 1 0 1 ...

  2. 2015 多校联赛 ——HDU5375(dp)

    Sample Input 2 00?0 1 2 4 8 ???? 1 2 4 8   Sample Output Case #1: 12 Case #2: 15 ?部分可以是0  or  1,将二进制 ...

  3. 2015多校.Zero Escape (dp减枝 && 滚动数组)

    Zero Escape Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Tot ...

  4. 2015 多校联赛 ——HDU5334(构造)

    Virtual Participation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Ot ...

  5. 2015 多校联赛 ——HDU5302(构造)

    Connect the Graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  6. 2015 多校联赛 ——HDU5294(最短路,最小切割)

    Tricks Device Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) To ...

  7. 2015 多校联赛 ——HDU5325(DFS)

    Crazy Bobo Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Tota ...

  8. 2015 多校联赛 ——HDU5316(线段树)

    Fantasy magicians usually gain their ability through one of three usual methods: possessing it as an ...

  9. 2015 多校联赛 ——HDU5323(搜索)

    Solve this interesting problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

随机推荐

  1. C简单实现动态顺序表

    <span style="font-size:18px;">一下为简单实现:</span> #define SIZE 3; typedef int Data ...

  2. shell中冒号 : 用途说明

    我们知道,在Linux系统中,冒号(:)常用来做路径的分隔符(PATH),数据字段的分隔符(/etc/passwd)等.其实,冒号(:)在Bash中也是一个内建命令,它啥也不做,是个空命令.只起到占一 ...

  3. ASP.NET MVC中错误处理方式

    /// <summary> /// 标记了HandleError,并指明错误处理页为AboutError.aspx /// </summary> /// <returns ...

  4. 儿童节,我们从零开始——Python入门资源推荐

    原创 2017-06-01 玄魂工作室 玄魂工作室 今天是六一儿童节,首先祝所有的小朋友身体健康,能永远生活在一个没有战争,没有压迫的世界里,永远快乐. 上一篇文章,很多人都对Python的各种书籍感 ...

  5. 《深入实践Spring Boot》阅读笔记之一:基础应用开发

    上上篇「1718总结与计划」中提到,18年要对部分项目拆分,进行服务化,并对代码进行重构.公司技术委员会也推荐使用spring boot,之前在各个技术网站中也了解过,它可以大大简化spring配置和 ...

  6. jmeter入门(02)测试报告各项指标含义

    一.名词定义(时间单位ms) 1.聚合报告 Sample:本次测试场景共运行多少个请求: Average:平均响应时间: Median:统计意义上的响应时间中值: 90% line:所有线程中90%的 ...

  7. hadoop2.6.0实践:A02 问题处理 util.NativeCodeLoader: Unable to load native-hadoop library for your platform

    ############################################################# hadoop "util.NativeCodeLoader: Un ...

  8. OAuth2.0学习(1-5)授权方式2-简化模式(implicit grant type)

    授权方式2-简化模式(implicit grant type) 简化模式(implicit grant type)不通过第三方应用程序的服务器,直接在浏览器中向认证服务器申请令牌,跳过了"授 ...

  9. 115 个 Java 面试题和答案——终极(上)

    目录 面向对象编程(OOP)常见的 Java 问题Java 线程Java 集合类垃圾收集器 面向对象编程(OOP) Java 是一个支持并发.基于类和面向对象的计算机编程语言.下面列出了面向对象软件开 ...

  10. Python 自动化 第一周

    1.Python简介 1.1.Python介绍 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆(中文名字:龟叔)为了在阿姆斯特丹打发时 ...