Files
python/TangDou/AcWing/1371_1.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

24 lines
650 B
C++
Raw Permalink 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.

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 30;
const int M = 1e4 + 10;
LL f[N][M];
int w[N];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d", &w[i]);
f[0][0] = 1; // 使用0种货币凑0元钱,也是一种方案。可以理解为是超级源点,有了它,每个基础货币价格才成为合法~
for (int i = 1; i <= n; i++)
for (int j = 0; j <= m; j++) {
for (int k = 0; k * w[i] <= j; k++)
f[i][j] += f[i - 1][j - k * w[i]];
}
printf("%lld\n", f[n][m]);
return 0;
}