LintCode - Backpack II
2015-04-06 13:26
399 查看
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 vector<int> result(m+1, 0); for (int i = 0; i < A.size(); i++) { for (int j = m; j >= A[i]; j--) { result[j] = max(result[j], result[j-A[i]] + V[i]); } } return result[m]; } };
相关文章推荐
- LintCode-BackPack II
- lintcode-medium-Backpack II
- 【LintCode】 Backpack II 背包问题II
- LintCode_516 Paint House II
- LintCode 70 二叉树的层次遍历 II
- lintcode----线段树的构造II
- lintcode 容易题:Merge Sorted Array II 合并排序数组 II
- [LintCode] Longest Increasing Continuous subsequence II
- [Lintcode]Backpack
- 【LintCode】翻转链表 II
- Lintcode: Permutation Index II
- lintcode-153-数字组合 II
- [LintCode]38.搜索二维矩阵 II
- lintcode --寻找旋转排序数组中的最小值 II
- 不同的二叉查找树 II -LintCode
- **[Lintcode]Ugly Number II 丑数 II
- LintCode-落单的数 II
- lintcode:Unique Binary Search Trees II
- lintcode-medium-Segment Tree Query II
- 【LintCode】 Best Time to Buy and Sell Stock II 买卖股票的最佳时机 II