Description

Given n items with size nums[i] which an integer array and all positive numbers. An integer target denotes the size of a backpack. Find the number of possible fill the backpack.

Each item may only be used once

Example

Given candidate items [1,2,3,3,7] and target 7,

A solution set is:
[7]
[1, 3, 3]

return 2

public class Solution {
/**
* @param nums: an integer array and all positive numbers
* @param target: An integer
* @return: An integer
*/
public int backPackV(int[] nums, int target) {
// Write your code here
int[] f = new int[target + 1];
f[0] = 1;
for (int i = 0; i < nums.length; ++i)
for (int j = target; j >= nums[i]; --j)
f[j] += f[j - nums[i]]; return f[target];
}
}

  

最新文章

  1. CSS3与页面布局学习总结(四)——页面布局大全
  2. [Unity3d]3D项目转换为VR项目(暴风魔镜SDK)
  3. (转)Tomcat7+Redis存储Session
  4. encache学习教程
  5. 菜鸟调错(七)——控制台中执行mvn命令后提示‘cmd’不是内部或外部命令
  6. opencv笔记3:trackbar简单使用
  7. mysql varchar类型转换int类型找出最大值
  8. .net控件Radiobuttonlist的简单应用
  9. Dynamics CRM2016 新功能之Solution enhancements
  10. 洛谷.4245.[模板]任意模数NTT(MTT/三模数NTT)
  11. 剑指offer——python【第54题】字符流中第一个不重复的字符
  12. 2190: [SDOI2008]仪仗队
  13. poj 3009 冰球 【DFS】求最小步数
  14. Django后端项目---- rest framework(4)
  15. Java1.7 HashMap 实现原理和源码分析
  16. Stack&amp;&amp;Queue
  17. effective VBA
  18. 8天学通MongoDB——第一天 基础入门(转)
  19. NodeJS 难点(网络,文件)的 核心 stream 四: writable
  20. 如何编写Makefile,一份由浅入深的Makefile全攻略

热门文章

  1. Java开发笔记(一百一十六)采用UDP协议的Socket通信
  2. python 之 网络编程(基于TCP协议的套接字通信操作)
  3. ES6之reduce和reduceRight方法应用实例
  4. CCF 2016-09-2 火车购票
  5. Java的集合整理
  6. ④ Python3.0字符串
  7. 使用jQuery开发accordion手风琴插件
  8. 【OO学习】OO第三单元作业总结
  9. &#39;adb&#39; 不是内部或外部命令,也不是可运行的程序 或批处理文件—解决方法
  10. jQuery 名称发生冲突怎么办【问题】