背包问题 II
来源:互联网 发布:淘宝 宝贝分类 编辑:程序博客网 时间:2024/04/29 14:49
给出n个物品的体积A[i]和其价值V[i],将他们装入一个大小为m的背包,最多能装入的总价值有多大?
样例
对于物品体积[2, 3, 5, 7]和对应的价值[1, 5, 2, 4], 假设背包大小为10的话,最大能够装入的价值为9。
注意
A[i], V[i], n, m均为整数。你不能将物品进行切分。你所挑选的物品总体积需要小于等于给定的m。
class Solution {public: /** * @param m: An integer m denotes the size of a backpack * @param A & V: Given n items with size A[i] and value V[i] * @return: The maximum value */ int backPackII(int m, vector<int> A, vector<int> V) { // write your code here int n = A.size(); int buf[m+1]; memset(buf, 0, sizeof(buf)); for (int i = 0; i < n; i++) { for (int j = m; j >= 1; j--) { if (j >= A[i]) { buf[j] = max(buf[j], V[i]+buf[j-A[i]]); } } } return buf[m]; }};
0 0
- LintCode-背包问题 II
- 背包问题 II
- LintCode : 背包问题 II
- LintCode : 背包问题 II
- 背包问题 II
- LintCode:背包问题 II
- 背包问题 II
- 背包问题II
- lintcode--背包问题II
- 背包问题-Bone Collector II
- lintcode-背包问题II-125
- Java实现-背包问题II
- LintCode:M-背包问题 II
- LintCode刷题--背包问题 II
- LintCode 125. 背包问题 II
- 【LintCode】 Backpack II 背包问题II
- 125.Backpack II-背包问题 II(中等题)
- NOJ 1984 比赛现场气氛营造问题II (完全背包)
- 网络爬虫Python试验
- UINavigationBar自定义返回按钮
- Set Matrix Zeroes
- Java基础知识学习
- HDU 1114 Piggy-Bank (完全背包)
- 背包问题 II
- FZU-2202-犯罪嫌疑人 -10.1训练赛
- linux 常用快捷键
- [iOS进阶]XMPPFramework 学习小结
- spring整合struts2、mybatis的配置
- leetcode17
- 一部走心作品 ——《捉妖记》 引发中国CG技术新浪潮
- ns-2与TCP拥塞模拟 之七 ns-2中自带的应用Ping解读
- PHP_EOL