AcWing 1021. 货币系统

题目传送门
【总结】背包问题的至多/恰好/至少

参阅\(AcWing\) \(1023\) 买书

#include <bits/stdc++.h>

using namespace std;
typedef long long LL;

const int N = 20;
const int M = 3010;
int n, m;
LL v[N];
LL f[M];

int main() {
    cin >> n >> m;
    //base case
    f[0] = 1;
    for (int i = 1; i <= n; i++) {
        cin >> v[i];
        for (int j = v[i]; j <= m; j++)
            f[j] += f[j - v[i]];
    }
    //一个整数,代表选择方案种数
    printf("%lld", f[m]);
    return 0;
}
原文地址:https://www.cnblogs.com/littlehb/p/15668438.html