2015 多校联赛 ——HDU5410(dp)
100 2
10 2 1
20 1 1
题意:共有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)的更多相关文章
- 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 ...
- 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,将二进制 ...
- 2015多校.Zero Escape (dp减枝 && 滚动数组)
Zero Escape Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Tot ...
- 2015 多校联赛 ——HDU5334(构造)
Virtual Participation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Ot ...
- 2015 多校联赛 ——HDU5302(构造)
Connect the Graph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- 2015 多校联赛 ——HDU5294(最短路,最小切割)
Tricks Device Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) To ...
- 2015 多校联赛 ——HDU5325(DFS)
Crazy Bobo Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Tota ...
- 2015 多校联赛 ——HDU5316(线段树)
Fantasy magicians usually gain their ability through one of three usual methods: possessing it as an ...
- 2015 多校联赛 ——HDU5323(搜索)
Solve this interesting problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
随机推荐
- 1013团队Beta冲刺日志集合帖
Beta预备 Beta冲刺day1 Beta冲刺day2 Beta冲刺day3 Beta冲刺day4 Beta冲刺day5 Beta冲刺day6 Beta冲刺day7 用户使用调查报告 Beta冲刺总 ...
- C语言--第四周作业
一.题目7-1 计算分段函数[1] 1.代码 #include <stdio.h> int main () { float x,result; scanf("%f",& ...
- django获取ip与数据重复性判定
获取ip if request.META.has_key('HTTP_X_FORWARDED_FOR'): ip_c = request.META['HTTP_X_FORWARDED_FOR'] el ...
- Fluent Interface(流式接口)
我最初接触这个概念是读自<<模式-工程化实现及扩展>>,另外有Martin fowler大师 所写http://martinfowler.com/bliki/FluentInt ...
- 【TensorFlow随笔】关于一个矩阵与多个矩阵相乘的问题
问题描述: Specifically, I want to do matmul(A,B) where 'A' has shape (m,n) 'B' has shape (k,n,p) and t ...
- 深入了解GOT,PLT和动态链接
之前几篇介绍exploit的文章, 有提到return-to-plt的技术. 当时只简单介绍了 GOT和PLT表的基本作用和他们之间的关系, 所以今天就来详细分析下其具体的工作过程. 本文所用的依然是 ...
- SpringBoot的注解:@SpringBootApplication注解 vs @EnableAutoConfiguration+@ComponentScan+@Configuration
spring Boot开发者经常使用@Configuration,@EnableAutoConfiguration,@ComponentScan注解他们的main类, 由于这些注解如此频繁地一块使用( ...
- 译《Time, Clocks, and the Ordering of Events in a Distributed System》
Motivation <Time, Clocks, and the Ordering of Events in a Distributed System>大概是在分布式领域被引用的最多的一 ...
- 日推20单词 Day01
1.conflict n. 冲突 2.electronic adj. 电子的 3.mine n. 矿藏,地雷 4.mineral n. 矿物质 adj. 矿物的 5.undermine vt 破坏,渐 ...
- MySql查询正在进行中的事务
用法 SELECT * FROM information_schema.INNODB_TRX 这个只能查询此刻正在进行中的事务,已经完成的是查不到的 表字段定义 The INFORMATION_SCH ...