Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 복서 정렬하기
- ElementTree
- 1174
- 순열장난
- 백트렉킹
- 백트랙킹
- 줄어드는 숫자
- 백준
- 10597
- 위클리 6주차
- 부분 수열의 합
- 문서자동화
- 몯느 순열
- openssl
- 좋은 수열
- 완전 탐색
- dfs
- 프로그래머스
- BOJ
- DP
- 39080
- BFS
- 그래프
- 백트래킹
- 입실 퇴실
- 재귀
- 너비우선탐색
- Java
- 위클리 챌린지
- 코딩테스트
Archives
개발자-H 입니다.
BOJ - 동전 0 본문
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
- 그리디 문제이다.
- 큰 동전부터 작은 동전 순으로 목표 K원을 나눠주면 된다.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
public static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws Exception {
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int K = Integer.parseInt(st.nextToken());
int[] coins = new int[N];
for (int i = 0; i < N; i++) {
coins[i] = Integer.parseInt(br.readLine());
}
int usedCoin = 0;
int remainWon = K;
for (int i = N - 1; i >= 0; i--) {
usedCoin += remainWon / coins[i];
remainWon = remainWon % coins[i];
}
System.out.println(usedCoin);
}
}
'Algorithm > 문제 풀이' 카테고리의 다른 글
BOJ - 좌표 정렬하기 (0) | 2021.08.28 |
---|---|
프로그래머스 - 카카오프렌즈 컬러링북 (0) | 2021.08.17 |
BOJ - ATM (0) | 2021.08.16 |
BOJ - 1, 2, 3 더하기 (0) | 2021.08.16 |
BOJ - 토마토 (7576) (0) | 2021.08.14 |
Comments