Skip to content

Commit 68bc1f7

Browse files
committed
feat : 인프런 냅색 알고리즘 동전교환
1 parent 3c050c9 commit 68bc1f7

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package sgyj.inflearn.yeji.section9;
2+
3+
import java.awt.print.Pageable;
4+
import java.util.Arrays;
5+
import java.util.Scanner;
6+
7+
// 동전교환
8+
public class Solution5 {
9+
private static int n, m;
10+
private static int[] dy;
11+
12+
private static int solution(int n, int[] coins, int result){
13+
Arrays.fill( dy,Integer.MAX_VALUE );
14+
dy[0] = 0;
15+
for(int i=0; i<n; i++){
16+
for(int j=coins[i]; j<=m; j++){
17+
dy[j]=Math.min( dy[j],dy[j-coins[i]]+1 );
18+
}
19+
}
20+
21+
return dy[m];
22+
}
23+
24+
public static void main ( String[] args ) {
25+
Scanner sc = new Scanner( System.in );
26+
int n = sc.nextInt();
27+
int[] arr = new int[n];
28+
for(int i=0; i<n; i++){
29+
arr[i] = sc.nextInt();
30+
}
31+
m = sc.nextInt();
32+
dy = new int[m+1];
33+
System.out.println(solution( n,arr,m ));
34+
}
35+
36+
}

0 commit comments

Comments
 (0)