We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 07ee06f commit efc8e12Copy full SHA for efc8e12
BOJ/gold/BOJ2294/src/Main.java
@@ -1,5 +1,34 @@
1
+import java.util.Arrays;
2
+import java.util.Scanner;
3
+
4
public class Main {
5
public static void main(String[] args) {
- 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
33
}
34
0 commit comments