【題解】CSES 1636 Coin Combinations II

【題目敘述】https://cses.fi/problemset/task/1636/
【解題想法】DP

#include <iostream>
using namespace std;
 
int n, x, c[105], dp[1000005], mod = 1e9+7;
 
int main() {
    cin >> n >> x;
    dp[0] = 1;
    for (int i = 0; i < n; i++){
        cin >> c[i];
        for (int j = 0; j+c[i] <= x; j++){
            dp[j+c[i]] += dp[j];
            dp[j+c[i]] %= mod;
        }
    }
    cout << dp[x];
}
分享本文 Share with friends