https://www.acmicpc.net/problem/11047
11047번: 동전 0
첫째 줄에 N과 K가 주어진다. (1 ≤ N ≤ 10, 1 ≤ K ≤ 100,000,000) 둘째 줄부터 N개의 줄에 동전의 가치 Ai가 오름차순으로 주어진다. (1 ≤ Ai ≤ 1,000,000, A1 = 1, i ≥ 2인 경우에 Ai는 Ai-1의 배수)
www.acmicpc.net
#include <iostream>
#include <stack>
using namespace std;
int main() {
int n, goal;
cin >> n >> goal;
stack<int> s;
for (int i = 0; i < n; i++) {
int input;
cin >> input;
s.push(input);
}
int result = 0;
while (true) {
if (goal - s.top() >= 0) {
if (goal != 0) {
result += goal / s.top();
goal = goal % s.top();
}
}
s.pop();
if (s.empty()) {
cout << result;
break;
}
}
}
설계