Skip to content

Commit 4c71fc3

Browse files
authored
Merge pull request #120 from AlgorithmWithGod/lkhyun
[20250214] BOJ / 골드3 / 동전 / 이강현
2 parents 736ae7c + 828263c commit 4c71fc3

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
```java
2+
import java.util.*;
3+
import java.io.*;
4+
public class Main{
5+
public static void main(String[] args) throws Exception{
6+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
8+
StringTokenizer st = new StringTokenizer(br.readLine());
9+
int X = Integer.parseInt(st.nextToken());
10+
11+
int[] info = new int[4];
12+
int[][] dp = new int[X+1][5];
13+
int[] coins = {1,5,10,25};
14+
for(int i=0;i<4;i++){
15+
info[i] = Integer.parseInt(st.nextToken());
16+
}
17+
for(int i=0;i<=X;i++){
18+
Arrays.fill(dp[i],-1);
19+
}
20+
for(int i=0;i<5;i++){
21+
dp[0][i] = 0;
22+
}
23+
for(int i=1;i<=X;i++){
24+
for(int j = 0;j<4;j++){
25+
if(dp[i][j]==-1){dp[i][j]=0;}
26+
if(i-coins[j]<0){
27+
continue;
28+
}
29+
if(dp[i-coins[j]][4]>dp[i][4]){
30+
if(info[j] > dp[i-coins[j]][j]){
31+
for(int k=0;k<=4;k++){
32+
dp[i][k] = dp[i-coins[j]][k];
33+
}
34+
dp[i][j]++;
35+
dp[i][4]++;
36+
}
37+
}
38+
}
39+
}
40+
for(int i=0;i<4;i++){
41+
bw.write(dp[X][i]+" ");
42+
}
43+
bw.flush();
44+
}
45+
}
46+
```

0 commit comments

Comments
 (0)