CSES: Coin Combinations I
CSES: Coin Combinations I
和Dice combination很像,dp[i]的定义还是一样,只需要微调一下,见代码:
/*
* Created by: Chixiyu
* Date: 2025-02-12
*/
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, x;
cin >> n >> x;
vector<int> a(n);
for (auto &it : a)
cin >> it;
vector<int> dp(x + 1, 0);
dp[0] = 1;
for (int i = 1; i <= x; i++) {
for (int j = 0; j < n; j++) {
if (i - a[j] >= 0) {
dp[i] += dp[i - a[j]];
dp[i] %= MOD;
}
}
}
cout << dp[x] << endl;
return 0;
}
评论
其他文章