注意j-A[i-1]必须大于等于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]
* @return: The maximum size
*/
int backPack(int m, vector<int> A) {
// write your code here
int length = A.size();
vector<vector<bool>> result(length+,vector<bool>(m+));
for(int i = ;i <= m;i++)
result[][i] = false;
for(int j = ;j <= length;j++)
result[j][] = true;
for(int i = ;i <= length;i++){
for(int j = ;j <= m;j++){
if((j-A[i-]) >= )
result[i][j] = result[i-][j-A[i-]] || result[i-][j];
else
result[i][j] = result[i-][j];
}
}
int max = ;
for(int i = ;i <= length;i++){
for(int j = ;j <= m;j++){
if(result[i][j] == true){
if(j > max)
max = j;
}
}
}
return max;
}
};

最新文章

  1. ref
  2. OC内存管理--zombie对象
  3. vue 单页面应用实战
  4. SDOI2008 Sandy的卡片( 后缀数组 )
  5. [bzoj3955] [WF2013]Surely You Congest
  6. chromedriver禁用图片,禁用js,切换UA
  7. bzoj2969 矩形粉刷
  8. Ubuntu16 编译源码安装MXNet 可变卷积Deformable-ConvNets GPU版
  9. React Native移植原生Android
  10. C# 操作Word文本框——插入表格/读取表格/删除表格
  11. MyCat读写分离-笔记(四)
  12. 解决git pull出现: Your local changes to the following files would be overwritten by merge: ...的问题
  13. Eclipse中的快捷键
  14. docker 小技巧 列出所有容器的IP地址
  15. [笔记]猿计划(WEB安全工程师养成之路系列教程):02HTML头部标签
  16. 解决centos 7.5安装openvpn,mirrors.163.com提示没有可用软件包openvpn、easy-rsa问题
  17. Eclipse导入jdk的源码
  18. C语言中关于逗号运算符的理解
  19. Emacs 文件中的查找操作
  20. KaTeX.js

热门文章

  1. git 的安装使用以及协作流程
  2. jQuery获取table当前所在行
  3. 让App飞久一点
  4. CF364D Ghd(随机化)
  5. [HNOI2010] 公交线路 bus
  6. java 阻塞队列(转)
  7. C - Aladdin and the Flying Carpet
  8. Maven - settings.xml里的offline节点的作用
  9. [已读]JavaScript语言精髓与编程实践
  10. js 正则验证url