Skip to content

Commit d197c2a

Browse files
authored
Merge pull request #413 from AlgorithmWithGod/suyeun84
[20250704] BOJ / G4 / 동전 바꿔주기 / 김수연
2 parents 1760f46 + 175a7a7 commit d197c2a

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class boj2624 {
6+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
static StringTokenizer st;
8+
static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());}
9+
static int nextInt() {return Integer.parseInt(st.nextToken());}
10+
11+
public static void main(String[] args) throws Exception {
12+
nextLine();
13+
int T = nextInt();
14+
nextLine();
15+
int k = nextInt();
16+
Coin[] coins = new Coin[k+1];
17+
int[][] dp = new int[T+1][k+1];
18+
19+
for (int i = 1; i <= k; i++) {
20+
nextLine();
21+
int p = nextInt();
22+
int n = nextInt();
23+
coins[i] = new Coin(p, n);
24+
}
25+
for (int i = 1; i <= k; i++) {
26+
int val = coins[i].val;
27+
int cnt = coins[i].cnt;
28+
dp[0][i - 1] = 1;
29+
30+
for (int j = 1; j <= cnt; j++) {
31+
for (int z = val * j; z <= T; z++) {
32+
dp[z][i] += dp[z - (val * j)][i - 1];
33+
}
34+
}
35+
36+
for (int j = 1; j <= T; j++) {
37+
dp[j][i] += dp[j][i - 1];
38+
}
39+
}
40+
41+
System.out.println(dp[T][k]);
42+
}
43+
static class Coin {
44+
int val, cnt;
45+
Coin(int val, int cnt) {
46+
this.val = val;
47+
this.cnt = cnt;
48+
}
49+
}
50+
}
51+
```

0 commit comments

Comments
 (0)