File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
src/main/java/sgyj/inflearn/yeji/section9 Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments