Skip to content

Commit efc8e12

Browse files
committed
0911
1 parent 07ee06f commit efc8e12

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

BOJ/gold/BOJ2294/src/Main.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,34 @@
1+
import java.util.Arrays;
2+
import java.util.Scanner;
3+
14
public class Main {
25
public static void main(String[] args) {
3-
System.out.println("Hello world!");
6+
Scanner sc =new Scanner(System.in);
7+
int N = sc.nextInt();
8+
int K = sc.nextInt();
9+
int [] dp = new int [K+1];
10+
Arrays.fill(dp,10001);
11+
int [] coinList = new int[N];
12+
for (int i=0; i<N;i++){
13+
int coin = sc.nextInt();
14+
coinList[i]=coin;
15+
16+
}
17+
18+
dp[0]=0;
19+
20+
for (int i=0; i< coinList.length; i++){
21+
for(int j=coinList[i]; j<K+1; j++){
22+
dp[j]=Math.min(dp[j],dp[j-coinList[i]]+1);
23+
24+
}
25+
}
26+
if (dp[K]==10001){
27+
System.out.println(-1);
28+
}else {
29+
System.out.println(dp[K]);
30+
}
31+
32+
433
}
534
}

0 commit comments

Comments
 (0)