We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent dd1a32f commit 9a60a68Copy full SHA for 9a60a68
backpack_vi.py
@@ -0,0 +1,20 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+class Solution:
4
+ # @param {int[]} nums an integer array and all positive numbers, no duplicates
5
+ # @param {int} target an integer
6
+ # @return {int} an integer
7
+ def backPackVI(self, nums, target):
8
+ # Write your code here
9
+ '''
10
+ 1. 先对nums排序
11
+ 2. 利用result[0]到result[i - 1]的结果迭代出result[i]
12
13
+ result = [0] * (target + 1)
14
+ result[0] = 1
15
+ nums.sort()
16
+ for i in xrange(1, target + 1):
17
+ for j in xrange(len(nums)):
18
+ if i >= nums[j]:
19
+ result[i] += result[i - nums[j]]
20
+ return result[-1]
0 commit comments