-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path8-5.cpp
More file actions
49 lines (42 loc) · 820 Bytes
/
8-5.cpp
File metadata and controls
49 lines (42 loc) · 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* @file 8-5.cpp
* @brief 효율적인 화폐 구성
* @author Sam Kim (samkim2626@gmail.com)
*
* d[i] : i원을 만들 수 있는 최소한의 화폐 개수
*/
#include <iostream>
using namespace std;
int coin[100], d[10001];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++)
{
cin >> coin[i];
}
fill_n(d, 10001, 10001);
d[0] = 0;
for (int i = 0; i < n; i++)
{
for (int j = coin[i]; j <= m; j++)
{
if (d[j - coin[i]] != 10001)
{
d[j] = min(d[j], d[j - coin[i]] + 1);
}
}
}
if (d[m] == 10001)
{
cout << -1 << '\n';
}
else
{
cout << d[m] << '\n';
}
return 0;
}