每日AC

每日AC

许诺 · 发布于 2025-03-17 · 浏览 398 回复 0
#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;

}

全部回复 共 0 条

还没有人回复。往下写第一条。

发表回复