2017-09-03 17:01:36

writer:pprp

这是一道多重背包裸题 - 记得是从右向左进行,还有几点需要注意啊,都在代码中表示出来了

代码如下:

/*
@theme:hdu2191 汶川地震
@writer:pprp
@begin:16:25
@end:16:59
@declare:多重背包问题
@error:方向是从左向右进行
@date:2017/9/3
*/ #include <bits/stdc++.h> using namespace std;
int M, N;//M money N kinds
const int maxn = ;
int w[maxn],v[maxn],num[maxn];
int dp[maxn*]; int main()
{
//freopen("in.txt","r",stdin);
int cas;
cin >> cas;
while(cas--)
{
memset(dp,,sizeof(dp));
cin >> M >> N;
for(int i = ; i <= N ; i++)
{
cin >> w[i] >> v[i] >> num[i];
} for(int i = ; i <= N; i++ )
{
for(int k = ; k <= num[i]; k++)//1、顺序无所谓
{
for(int j = M; j >= w[i] ; j--)//2、从右向左进行
{
dp[j] = max(dp[j],dp[j-w[i]]+v[i]);//3、由于已经有重复次数了,所以就没有必要做k*w[i]的工作了
}
}
}
cout << dp[M] << endl;
} return ;
}

解题报告:hdu2191汶川地震 - 多重背包模板的更多相关文章

  1. HDU 2191 珍惜现在,感恩生活(多重背包模板题)

    多重背包模板题 #include<iostream> #include<cstring> #include<algorithm> using namespace s ...

  2. 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活--hdu2191(多重背包模板)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2191 标准的多重背包 题目 有N种物品和一个容量为V的背包.第i种物品最多有n[i]件可用,每件费用是 ...

  3. HDU--2191 汶川地震购米(多重背包)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=2191 分析:有资金n元,而市场有m种大米,每种大米价格不等,重量不等,数量不等, 并且只能整袋购买.如何用 ...

  4. hdu2844Coins(多重背包模板)

    Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  5. hdu2191 悼念512汶川大地震 ——多重背包

    link:http://acm.hdu.edu.cn/showproblem.php?pid=2191 最简单的那种 #include <iostream> #include <cs ...

  6. [51nod]多重背包模板

    https://www.51nod.com/tutorial/course.html#!courseId=11 题目大意: 有$N$种物品和一个容量为$W$的背包.第$i$种物品最多有$c[i]$件可 ...

  7. 【多重背包模板】poj 1014

    #include <iostream> #include <stdio.h> #include <cstring> #define INF 100000000 us ...

  8. 多重背包模板 51Nod 1086

    有N种物品,每种物品的数量为C1,C2......Cn.从中任选若干件放在容量为W的背包里,每种物品的体积为W1,W2......Wn(Wi为整数),与之相对应的价值为P1,P2......Pn(Pi ...

  9. 解题报告+板子:luogu P3387 【模板】缩点

    题目链接:P3387 [模板]缩点 缩点板子,所谓\(dp\)就是拓扑排序(毕竟可以重走边),像\(SPFA\)一样松弛就好,就是重边极其烦人,还加了排序(绝对自己想的,然鹅拓扑的思路不是). 下面上 ...

随机推荐

  1. jquery的强大选择器

    $("#myELement")    选择id值等于myElement的元素,id值不能重复在文档中只能有一个id值是myElement所以得到的是唯一的元素 $("di ...

  2. 【JVM】线上应用故障排查

    高CPU占用 一个应用占用CPU很高,除了确实是计算密集型应用之外,通常原因都是出现了死循环. 根据top命令,发现PID为28555的Java进程占用CPU高达200%,出现故障. 通过ps aux ...

  3. python和shell之间变量的相互调用

    python -> shell: 1.环境变量 2.字符串连接 3.通过管道 import os var=’123’ os.popen(’wc -c’, ’w’).write(var) 4.通过 ...

  4. python 的弹框

    import easygui easygui.msgbox("This is a message!", title="simple gui")

  5. Uboot mmc命令解析&NAND flash uboot命令详解

    转载:http://blog.csdn.net/simonjay2007/article/details/43198353 一:mmc的命令如下: 1:对mmc读操作 mmc read addr bl ...

  6. 漫谈DOM 事件流的三个阶段

    一丶 流 什么是流? 比如 react 中的单项数据流,Node.js 中的流,或者本文中的 DOM 事件流,都是流的具体体现.专业地讲,流是程序输入或输出的一个连续的字节序列:通俗地讲,流是有方向的 ...

  7. Look for this newest GS Jordan 6 Floral

    Named 'Bulls Over Broadway' and 'Gym Red', the most recent variation from the New Jordans 2015 is fo ...

  8. mac 安装Sequel Pro

    安装命令如下 Install the App Press Command+Space and type Terminal and press enter/return key. Run in Term ...

  9. smarty模板(转载)

    一.smarty的程序设计部分: 在smarty的模板设计部分我简单的把smarty在模板中的一些常用设置做了简单的介绍,这一节主要来介绍一下如何在smarty中开始我们程序设计.下载Smarty文件 ...

  10. PKU 2559 Largest Rectangle in a Histogram(单调栈)

    题目大意:原题链接 一排紧密相连的矩形,求能构成的最大矩形面积. 为了防止栈为空,所以提前加入元素(-1,0) #include<cstdio> #include<stack> ...