Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "bits/stdc++.h"
- const int max = 1000000007;
- int main()
- {
- int n, x;
- std::cin >> n >> x;
- std::vector<int> coins(n);
- std::vector<int> numebrOfCoins(x + 1, 1000000000);
- for (int i = 0; i < n; i++)
- {
- std::cin >> coins[i];
- }
- numebrOfCoins[0] = 0;
- for (int value = 1; value <= x; value++)
- {
- for (int j = 0; j < n; j++)
- {
- if (value - coins[j] >= 0)
- {
- numebrOfCoins[value] = std::min(numebrOfCoins[value], numebrOfCoins[value - coins[j]] + 1);
- }
- }
- }
- if (numebrOfCoins[x] != 1000000000)
- {
- std::cout << numebrOfCoins[x];
- }
- else
- {
- std::cout << -1;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement