-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathgreedy
More file actions
44 lines (36 loc) · 816 Bytes
/
greedy
File metadata and controls
44 lines (36 loc) · 816 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
// C++ program to find minimum
// number of denominations
#include <bits/stdc++.h>
using namespace std;
// All denominations of Indian Currency
int denomination[] = { 1, 2, 5, 10, 20,
50, 100, 500, 1000 };
int n = sizeof(denomination) / sizeof(denomination[0]);
void findMin(int V)
{
sort(denomination, denomination + n);
// Initialize result
vector<int> ans;
// Traverse through all denomination
for (int i = n - 1; i >= 0; i--) {
// Find denominations
while (V >= denomination[i]) {
V -= denomination[i];
ans.push_back(denomination[i]);
}
}
// Print result
for (int i = 0; i < ans.size(); i++)
cout << ans[i] << " ";
}
// Driver Code
int main()
{
int n = 93;
cout << "Following is minimal"
<< " number of change for " << n
<< ": ";
//Function Call
findMin(n);
return 0;
}