每日AC

许诺  •  28天前


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {

int V, N;
cin >> V >> N;
vector<int> coins;
for (int i = 0; i < V; ++i) {
    int c;
    cin >> c;
    coins.push_back(c);
}
sort(coins.begin(), coins.end());
auto last = unique(coins.begin(), coins.end());
coins.erase(last, coins.end());

vector<long long> dp(N + 1, 0);
dp[0] = 1;

for (int coin : coins) {
    if (coin > N) continue; 
    for (int j = coin; j <= N; ++j) {
        dp[j] += dp[j - coin];
    }
}

cout << dp[N] << endl;

return 0;

}


评论:

请先登录,才能进行评论