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. python 将日期戳(五位数时间)转换为标准时间

    5位数日期戳 读取 .mat 文件处理里面数据时,发现里面的日期数据全部都是 “5位数” 数字,很不解: 后来查到可以在excel中通过设置单元格调回标准日期格式,如下: 选中日期戳,右键选择 “格式 ...

  2. 前端之masonry(图片瀑布流插件)

    加载代码: 1 2 <script src="http://libs.baidu.com/jquery/1.8.3/jquery.min.js"></script ...

  3. sipp模拟freepbx分机测试(SIP协议调试)

    1.sipp的安装 1) 在centos 7.2下安装 yum install make gcc gcc-c++ ncurses ncurses.x86_64 ncurses-devel ncurse ...

  4. Using Bluetooth LE with Go (Golang)

    Using Bluetooth LE with Go (Golang)  Gatt is a Go package, which provides developers to create BLE a ...

  5. (转)全局变量、extern/static/const区别与联系

    全局变量.extern/static/const区别与联系 编译单元(模块):     在IDE开发工具大行其道的今天,对于编译的一些概念很多人已经不再清楚了,很多程序员最怕的就是处理连接错误(LIN ...

  6. IOS中程序如何进行推送消息(本地推送,远程推送)2(下)

    内容中包含 base64string 图片造成字符过多,拒绝显示

  7. To keep up-to-date with Latest Jordans 2016

    The Latest Jordans 2016 will feature cement speckling because the base, Reflect Silver accents, a a ...

  8. 解决wordcloud导出图片不清楚

    使用WordCloud生成词云图片 本文详细介绍参考自:https://www.jianshu.com/p/fdd0acccf1c5 wordcloud开源项目:https://github.com/ ...

  9. modelform 使用

    modelForm (1) model的知识点: class UserInfo(AbstractUser): tel = models.CharField(max_length=32) gender ...

  10. 【android】使用RecyclerView和CardView,实现知乎日报精致布局

    完整代码,请参考我的博客园客户端,git地址:http://git.oschina.net/yso/CNBlogs 在写博客园客户端的时候,突然想到,弄个知乎日报风格的简单清爽多好!不需要那么多繁杂的 ...