背包问题2 (lintcode)
这里:
for(int j = 1;j <= m;j++)
result[0][j] = 0x80000000;
不能从0开始,result[0][0]是可以取到的,是0。其他情况取不到才用最小表示。
class Solution {
public:
/*
* @param m: An integer m denotes the size of a backpack
* @param A: Given n items with size A[i]
* @param V: Given n items with value V[i]
* @return: The maximum value
*/
int backPackII(int m, vector<int> &A, vector<int> &V) {
// write your code here
int length = A.size();
vector<vector<int>> result(length+,vector<int>(m+));
for(int i = ;i <= length;i++)
result[i][] = ;
for(int j = ;j <= m;j++)
result[][j] = 0x80000000;
for(int i = ;i <= length;i++){
for(int j = ;j <= m;j++){
if((j - A[i-]) >= )
result[i][j] = max(result[i-][j-A[i-]] + V[i-],result[i-][j]);
else
result[i][j] = result[i-][j];
}
}
int max = ;
for(int i = ;i <= m;i++){
if(result[length][i] > max)
max = result[length][i];
}
return max;
}
};
背包问题2 (lintcode)的更多相关文章
- lintcode-125-背包问题 II
125-背包问题 II 给出n个物品的体积A[i]和其价值V[i],将他们装入一个大小为m的背包,最多能装入的总价值有多大? 注意事项 A[i], V[i], n, m均为整数.你不能将物品进行切分. ...
- lintcode:背包问题II
背包问题II 给出n个物品的体积A[i]和其价值V[i],将他们装入一个大小为m的背包,最多能装入的总价值有多大? 注意事项 A[i], V[i], n, m均为整数.你不能将物品进行切分.你所挑选的 ...
- lintcode:背包问题
背包问题 在n个物品中挑选若干物品装入背包,最多能装多满?假设背包的大小为m,每个物品的大小为A[i] 样例 如果有4个物品[2, 3, 5, 7] 如果背包的大小为,可以选择的空间. 如果背包的大小 ...
- 92.背包问题(lintcode)
注意j-A[i-1]必须大于等于0,只大于0会报错 class Solution { public: /** * @param m: An integer m denotes the size of ...
- leetcode & lintcode for bug-free
刷题备忘录,for bug-free leetcode 396. Rotate Function 题意: Given an array of integers A and let n to be it ...
- leetcode & lintcode 题解
刷题备忘录,for bug-free 招行面试题--求无序数组最长连续序列的长度,这里连续指的是值连续--间隔为1,并不是数值的位置连续 问题: 给出一个未排序的整数数组,找出最长的连续元素序列的长度 ...
- lintcode 题目记录3
Expression Expand Word Break II Partition Equal Subset Sum Expression Expand 字符串展开问题,按照[]前的数字展开字符 ...
- lintcode算法周竞赛
------------------------------------------------------------第七周:Follow up question 1,寻找峰值 寻找峰值 描述 笔记 ...
- [LintCode]——目录
Yet Another Source Code for LintCode Current Status : 232AC / 289ALL in Language C++, Up to date (20 ...
随机推荐
- 甩掉 ashx/asmx,使用jQuery.ajaxWebService请求WebMethod,Ajax处理更加简练
在WebForm下 开发ajax程序,需要借助于一般处理程序(*.ashx)或web服务(*.asmx),并且每一个ajax请求,都要建一个这样的文件,如此一来,如果在一个项目中ajax程序多了,势必 ...
- ES6之Promise对象学习——8个例子学会Promise
目录 Promise 立即执行 Promise 三种状态 Promise 不可逆性 链式调用 Promise.then()回调异步性 Promise中的异常 Promise.resolve() res ...
- String.Format 大全
0.0的格式化 string.Format("{0:8D8}", 3)//第一个8表示空8个位置,后一个8表示用0填写最多8位数据 1.格式化货币(跟系统的环境有关,中文系统默认格 ...
- 【渗透测试】如何使用burpsuite对特殊密码进行爆破
爆破是渗透测试中必不可少的一部分,对于没有太大价值可利用的漏洞或是业务只有一个登陆页面时,爆破更是我们的最合适的选择.那么在爆破时,抛去目标系统对爆破频率的限制,如果遇到较为复杂的密码,该如何顺利进行 ...
- 【UVA - 10815】Andy's First Dictionary (set)
Andy's First Dictionary Description 不提英文了 直接上中文大意吧 XY学长刚刚立下了再不过CET就直播xx的flag,为了不真的开启直播模式,XY学长决定好好学习英 ...
- G - B-number
#include<stdio.h> #include<string.h> using namespace std; typedef long long ll; ]; ][][] ...
- 关于log
如果项目上过线的话,那你一定知道Log是多么重要. 为什么说Log重要呢?因为上线项目不允许你调试,你只能通过Log来分析问题.这时打一手好Log的重要性绝不亚于写一手好代码.项目出问题时,你要能拿出 ...
- android webview.goback 问题
重写 shouldOverrideUrlLoading 不需要实现 view.loadUrl(url);直接return false;即可 如果实现了,则使用window.location.repla ...
- HDU - 6312( 2018 Multi-University Training Contest 2)
bryce1010模板 http://acm.hdu.edu.cn/showproblem.php?pid=6312 输出前几项,都是"Yes" #include <bits ...
- 用python将多个文档合成一个
可以参考下以下网址(读写文件):https://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/ ...