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. Android Notification setLatestEventInfo方法已废弃

    代替setLatestEventInfo的方法是用Notification.Builder创建Builder对象,通过该对象设置Notification相关属性. otification.Builde ...

  2. SELinux与进程管理

  3. Java面试题合集(一)

    接下来几篇文章准备系统整理一下有关Java的面试题,分为基础篇,javaweb篇,框架篇,数据库篇,多线程篇,并发篇,算法篇等等,陆续更新中. 其他方面如前端后端等等的面试题也在整理中,都会有的. 所 ...

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

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

  5. egg.js 的优缺点

    egg.js 的优缺点 优点 所有的 web开发的点都考虑到了 agent 很有特色 文件夹规划到位 扩展能力优秀 缺点 最大的问题在于: 使用 loader 加载之后,失去了代码提示的能力 监控和运 ...

  6. javascript改变style样式和css样式

    转载 在很多情况下,都需要对网页上元素的样式进行动态的修改.在JavaScript中提供几种方式动态的修改样式,下面将介绍方法的使用.效果.以及缺陷. 1.使用obj.className来修改样式表的 ...

  7. ubuntu 虚拟机上的 django 服务,在外部Windows系统上无法访问

    背景介绍 今天尝试着写了一个最简单的django 服务程序,使用虚拟机(Ubuntu16.02 LTS)上的浏览器访问程序没有问题.但是在物理机器上(win10 Home) 就出现错误 解决方法 在 ...

  8. 19届华为实习生笔试之判断iPv6地址类型

    题二: 答案: #coding=utf-8 import re,sys str = sys.stdin.readline().strip() def regex(str): result = &quo ...

  9. Java8新特性第1章(Lambda表达式)

    在介绍Lambda表达式之前,我们先来看只有单个方法的Interface(通常我们称之为回调接口): public interface OnClickListener { void onClick(V ...

  10. Python REST

    Django REST framework 1. 什么是REST REST与技术无关,代表的是一种软件架构风格,REST是Representational State Transfer的简称,中文翻译 ...