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. [转帖]都在说DCEP,央行数字货币究竟跟你有什么关系?

    都在说DCEP,央行数字货币究竟跟你有什么关系? https://kuaibao.qq.com/s/20191104A0G1D300?refer=spider   黄奇帆指出,DCEP 使得交易环节对 ...

  2. Django-model更上层楼

    一 QuerySet对象 1.1可切片 使用Python 的切片语法来限制查询集记录的数目 .它等同于SQL 的LIMIT 和OFFSET子句. Entry.objects.all()[:5] # ( ...

  3. Ubuntu下载搜狗输入法

    实在...因为百度上写的就很好了,所以这里就直接“链”了.. https://jingyan.baidu.com/article/2d5afd6933a67b85a2e28e9f.html

  4. Fanuc Cnc 数控系统,PC端下发NC程序到CNC端,现场测试通过。

    1.这几天把FANUC 数据采集(产量,状态,轴负载等),以及NC程序下发封装成独立的dll,方便其它项目调用,自己顺便写了下demo测试,在车间测试了几天,效果很好,完善了许多细节. 2.大概的界面 ...

  5. ColorMatrixFilter色彩矩阵滤镜

    ColorMatrixFilter色彩矩阵滤镜: /** * * *----------------------------------------* * | *** ColorMatrixFilte ...

  6. [洛谷P5377][THUPC2019]鸽鸽的分割

    题目大意:有一个圆,圆上有$n$个点,将这几个点两两连接,问最多分成几部分 题解:发现这相当于一个平面图,由欧拉公式得($F$为平面分割块数,$E$为平面图边数,$V$为平面图点数):$$F=E-V+ ...

  7. AGC028E High Elements 贪心、DP、线段树

    传送门 看到要求"字典序最小"的方案,一个很直观的想法是按位贪心,那么我们需要check的就是当某一个数放在了第一个序列之后是否还存在方案. 假设当前两个序列的最大值和前缀最值数量 ...

  8. PCL提取圆柱系数

    网上看了很多教程,没看到圆柱提取后的系数解释. 源码如下: #include <pcl/ModelCoefficients.h> #include <pcl/io/pcd_io.h& ...

  9. C语言中特殊字符含义

    字符 中文 英文 说明  \n  换行符  newline     \t      Tab键  \b    backspace  退格键                        

  10. Linux定时清理日志脚本

    在应用疯狂打日志的情况下,服务器很容易被塞满磁盘. 先要写一个shell脚本,脚本如下. #!/bin/bash #----------------使用规范---------------- #1.该文 ...