leetcode-master/problems/0518.零钱兑换II.md

42 lines
1.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 计算有多少种方式
// 完全背包 for循环的顺序啊先是哪个for 后是哪个for定不下来
排列
```
class Solution {
public:
int change(int amount, vector<int>& coins) {
int dp[50001] = {0};
dp[0] = 1;
for (int i = 0; i <= amount; i++) {
for (int j = 0; j < coins.size(); j++) { // 这是组合把???
if (i - coins[j] >= 0) dp[i] += dp[i - coins[j]];
}
for (int j = 0; j <= amount; j++) {
cout << dp[j] << " ";
}
cout << endl;
}
return dp[amount];
}
};
```
这个才是组合,本题的题解,
```
class Solution {
public:
int change(int amount, vector<int>& coins) {
int dp[50001] = {0};
dp[0] = 1;
for (int i = 0; i < coins.size(); i++) { // 一个钱币只在序列里出现一次
for (int j = 0; j <= amount; j++) {
if (j - coins[i] >= 0) dp[j] += dp[j - coins[i]];
}
}
return dp[amount];
}
};
```