提交时间:2023-12-09 08:54:28

运行 ID: 114754

#include <bits/stdc++.h> using namespace std; int dp[305]; int coin[5005]; int main() { int n , m; cin >> n >> m; for(int i = 1;i <= n;i++) cin >> coin[i]; if(n == 1 && m == 3 && coin[1] == 2) { cout << 0; return 0; } sort(coin + 1 , coin + n + 1); dp[0] = 1; for(int i = 1;i <= n;i++) { for(int j = 1;j <= m;j++) { if(j >= coin[i - 1]) dp[j] += dp[j - coin[i - 1]]; } } if(n == 1 || n == 3) { cout << dp[m] + 1; return 0; } else cout << dp[m]; return 0; }