Skip to content

Commit 34706a1

Browse files
authored
Merge pull request #595 from AlgorithmWithGod/suyeun84
[20250802] BOJ / G5 / Coins / 김수연
2 parents 7d4402c + e632f61 commit 34706a1

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

suyeun84/202508/02 BOJ Coins.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class boj3067 {
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+
for (int tc = 1; tc <= T; tc++) {
15+
nextLine();
16+
int N = nextInt();
17+
int[] coins = new int[N+1];
18+
nextLine();
19+
for (int i = 1; i <= N; i++) coins[i] = nextInt();
20+
nextLine();
21+
int M = nextInt();
22+
int[][] dp = new int[N+1][M+1];
23+
for (int i = 1; i <= N; i++) {
24+
dp[i][0] = 1;
25+
for (int j = 1; j <= M; j++) {
26+
dp[i][j] = dp[i-1][j];
27+
if (j >= coins[i]) dp[i][j] += dp[i][j-coins[i]];
28+
}
29+
}
30+
System.out.println(dp[N][M]);
31+
}
32+
}
33+
}
34+
```

0 commit comments

Comments
 (0)