Created
September 13, 2016 16:20
-
-
Save patemotter/5773e7fbb301c382745e0fdb454b1f55 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
/** | |
* @param nums an integer array and all positive numbers, no duplicates | |
* @param target an integer | |
* @return an integer | |
*/ | |
int backPackVI(vector<int>& nums, int target) { | |
vector<int> dp(target + 1, 0); | |
dp[0] = 1; | |
for (int i = 1; i <= target; i++) { | |
for (int j = 0; j < nums.size(); j++) { | |
if (nums[j] <= i) { | |
dp[i] += dp[i - nums[j]]; | |
} | |
} | |
} | |
return dp[target]; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment