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];
}
}

  

Backpack V的更多相关文章

  1. Java Algorithm Problems

    Java Algorithm Problems 程序员的一天 从开始这个Github已经有将近两年时间, 很高兴这个repo可以帮到有需要的人. 我一直认为, 知识本身是无价的, 因此每逢闲暇, 我就 ...

  2. Backpack | & ||

    Backpack | Given n items with size Ai, an integer m denotes the size of a backpack. How full you can ...

  3. LintCode "Backpack"

    A simple variation to 0-1 Knapsack. class Solution { public: /** * @param m: An integer m denotes th ...

  4. LeetCode Backpack

    Given n items with size Ai, an integer m denotes the size of a backpack. How full you can fill this ...

  5. Backpack III

    Description Given n kinds of items, and each kind of item has an infinite number available. The i-th ...

  6. Backpack II

    Description There are n items and a backpack with size m. Given array A representing the size of eac ...

  7. J a v a 的“多重继承”

    接口只是比抽象类“更纯”的一种形式.它的用途并不止那些.由于接口根本没有具体的实施细节——也就是说,没有与存储空间与“接口”关联在一起——所以没有任何办法可以防止多个接口合并到一起.这一点是至关重要的 ...

  8. Exception in thread "main" java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(I)V

    在学习CGlib动态代理时,遇到如下错误: Exception in thread "main" java.lang.NoSuchMethodError: org.objectwe ...

  9. [Erlang 0118] Erlang 杂记 V

       我在知乎回答问题不多,这个问题: "对你职业生涯帮助最大的习惯是什么?它是如何帮助你的?",我还是主动回答了一下.    做笔记 一开始笔记软件做的不好的时候就发邮件给自己, ...

随机推荐

  1. ERP解析外围系统json数据格式

    外围系统调用ERP的WebService接口,将数据以json格式传到ERP,ERP解析json 1.创建java source jsp,提供java方法解析json数据 create or repl ...

  2. C++—多态与继承

    一.基本概念 1.类的继承,是新的类从已有类那里得到已有的特性.或从已有类产生新类的过程就是类的派生.原有的类称为基类或父类,产生的新类称为派生类或子类. 2.派生类的声明: class 派生类名:继 ...

  3. 阅读笔记——《How a Facebook rejection pushed me to start and grow a profitable business in 12 months》

    阅读笔记——<How a Facebook rejection pushed me to start and grow a profitable business in 12 months> ...

  4. (二) Windows 进行 Docker CE 安装(Docker Desktop)

    参考并感谢 官方文档: https://docs.docker.com/docker-for-windows/install/ 下载地址 https://download.docker.com/win ...

  5. Logback+ELK+SpringMVC搭建日志收集服务器

    (转) 1.ELK是什么? ELK是由Elasticsearch.Logstash.Kibana这3个软件的缩写. Elasticsearch是一个分布式搜索分析引擎,稳定.可水平扩展.易于管理是它的 ...

  6. 1+X学习日志——导航栏demo

    初级菜鸟的作品,各位大佬见笑了   <!DOCTYPE html> <html lang="en"> <head>     <meta c ...

  7. js(es6)数组去重

    // 利用set.reduce.filter去重 // Set function getSetArr(arr) { return [...new Set(arr)] } console.log(get ...

  8. CentOS 7 - 里面如何以root身份使用图形界面管理文件?

    nautilus 是gnome的文件管理器,但是如果不是root账号下,权限受限,我们可以通过以下方式以root权限使用! 启动shll,随后在shell里面输入下面命令: sudo nautilus

  9. Fortify漏洞之Denial of Service: Regular Expression

    继续对Fortify的漏洞进行总结,本篇主要针对  Denial of Service: Regular Expression  漏洞进行总结,如下: 1.Denial of Service: Reg ...

  10. 【idea】scala&sbt+idea安装配置与测试

    一.IDEA安装 下载Community版的IDEA,Ultimate是免费试用版(相当于用到后面要给钱的) ideaIC-2019.2.3.tar.gz 解压IDEA: tar -zxvf idea ...