Lintcode- 562.Backpack IVFollow
Description
Given n items with size nums[i]
which an integer array and all positive numbers, no duplicates. An integer target
denotes the size of a backpack. Find the number of possible fill the backpack.
1 | Each item may be chosen unlimited number of times |
Have you met this question in a real interview? Yes
Problem Correction
Example
Given candidate items [2,3,6,7]
and target 7
,
1 | A solution set is: |
return 2
Analyst
最后一步
F[n][m]
表示前n
个有 多少种方式拼出m
最后一个选上:
F[n][m] = Sum(F[n-1][m-A[ki]])
最后一个不选上:
F[n][m] = F[n-1][m]
顺序从小到大
边界情况
F[k][0] = 1
Code
1 |
|