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