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

23 lines
727 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;
const int N = 110;
const int M = 10010;
int a[N], f[N][M];
int n, m;
int main() {
cin >> n >> m;
for (int i = 1; i <= n; ++i)cin >> a[i];
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j) {
//正好相等,方案数+1
if (j == a[i])f[i][j] = f[i - 1][j] + 1;
//如果大于不选就是原来的方案数选了那么就依赖于j-a[i]这些钱在i-1个物品中的方案数
if (j > a[i]) f[i][j] = f[i - 1][j] + f[i - 1][j - a[i]];
//如果小于,没的选择
if (j < a[i]) f[i][j] = f[i - 1][j];
}
cout << f[n][m];
return 0;
}