Backpack V
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的更多相关文章
- Java Algorithm Problems
Java Algorithm Problems 程序员的一天 从开始这个Github已经有将近两年时间, 很高兴这个repo可以帮到有需要的人. 我一直认为, 知识本身是无价的, 因此每逢闲暇, 我就 ...
- Backpack | & ||
Backpack | Given n items with size Ai, an integer m denotes the size of a backpack. How full you can ...
- LintCode "Backpack"
A simple variation to 0-1 Knapsack. class Solution { public: /** * @param m: An integer m denotes th ...
- LeetCode Backpack
Given n items with size Ai, an integer m denotes the size of a backpack. How full you can fill this ...
- Backpack III
Description Given n kinds of items, and each kind of item has an infinite number available. The i-th ...
- Backpack II
Description There are n items and a backpack with size m. Given array A representing the size of eac ...
- J a v a 的“多重继承”
接口只是比抽象类“更纯”的一种形式.它的用途并不止那些.由于接口根本没有具体的实施细节——也就是说,没有与存储空间与“接口”关联在一起——所以没有任何办法可以防止多个接口合并到一起.这一点是至关重要的 ...
- Exception in thread "main" java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(I)V
在学习CGlib动态代理时,遇到如下错误: Exception in thread "main" java.lang.NoSuchMethodError: org.objectwe ...
- [Erlang 0118] Erlang 杂记 V
我在知乎回答问题不多,这个问题: "对你职业生涯帮助最大的习惯是什么?它是如何帮助你的?",我还是主动回答了一下. 做笔记 一开始笔记软件做的不好的时候就发邮件给自己, ...
随机推荐
- unexpected end of file while looking for precompiled headerdirective Add directive to 'stdafx.h' or rebuild precompiled header错误
解决方式: 项目工程右键->propertity(属性),选择不用于预编译头 原因: C++的编译过程如下: 当头文件很多时,预编译过程需要耗费大量时间,为了减少重复编译的次数,C和C++提供了 ...
- python基础 — 致初学者的天梯
Python简介 Python是一种计算机程序设计语言.是一种面向对象的动态类型语言,最初被设计用于编写自动化脚本(shell),随着版本的不断更新和语言新 功能的添加,越来越多被用于独立的.大型项目 ...
- Django 报错 admin.E408 admin.E409 admin.E410
报错内容 ERRORS: ?: (admin.E408) 'django.contrib.auth.middleware.AuthenticationMiddleware' must be in MI ...
- python函数知识七 闭包、装饰器一(入门)、装饰器二(进阶)
21.闭包 闭包:在嵌套函数内,使用非全局变量(且不使用本层变量) 闭包的作用:1.保证数据的安全性(纯洁度).2.装饰器使用 .__closure__判断是否是闭包 def func(): a = ...
- STL对map排序
// sort start typedef struct{ ... }Node; // Map的键是字符串,值是结构体.虽然有自动排序特性,但是按字符串的排序并不能符合要求.此时,Map的key可以视 ...
- web渗透思维导图
更新中!!
- nRF24L01/nRF24L01+应用总结
nRF24L01+是nRF24L01的升级款,比较显眼的区别是nRF24L01+比nRF24L01多了一个250Kbps传输速率.其它的还有接收模式官方给的耗电量是不一样的.个别寄存器名字不一样. 接 ...
- Detecting GAN-generated Imagery using Color Cues
Abstract 论文创新点:分析流行GAN网络结构得知,GAN网络生成得图片在颜色处理与真实摄像机拍摄的照片存在不同,主要表现在两方面. 实验结果:证明了两种线索能够有效区分GAN生 ...
- 1. RDD概念
1.1 RDD为什么会产生? RDD 是 Spark 的基石,是实现 Spark 数据处理的核心抽象.那么 RDD 为 什么会产生呢? Hadoop 的 MapReduce 是一种基于数据集的工作模式 ...
- jquery easyui datagrid 在翻页以后仍能记录被选中的行及刷新设置选中行数据
//easyUI的datagrid在复选框多选时,如何在翻页以后仍能记录被选中的行://注意datagrid中需要配置idField属性,一般为数据的主键 $.ajax({ type: 'GET', ...