📜  硬币组合 1 cses 解决方案 - 任何代码示例

📅  最后修改于: 2022-03-11 15:00:03.027000             🧑  作者: Mango

代码示例1
#include using namespace std;using ll = long long;using vi = vector;#define pb push_back#define rsz resize#define all(x) begin(x), end(x)#define sz(x) (int)(x).size()using pi = pair;#define f first#define s second#define mp make_pairvoid setIO(string name = "") { // name is nonempty for USACO file I/O    ios_base::sync_with_stdio(0); cin.tie(0); // see Fast Input & Output    if(sz(name)){        freopen((name+".in").c_str(), "r", stdin); // see Input & Output        freopen((name+".out").c_str(), "w", stdout);    }}
ll dp[1000001];
const int MOD = (int) 1e9 + 7;
int main(){    int n, x; cin >> n >> x;    vi coins(n);    for (int i = 0; i < n; i++) {        cin >> coins[i];    }    dp[0] = 1;    for (int weight = 0; weight <= x; weight++) {        for (int i = 1; i <= n; i++) {            if(weight - coins[i - 1] >= 0) {                dp[weight] += dp[weight - coins[i - 1]];                dp[weight] %= MOD;            }        }    }    cout << dp[x] << '\n';}