Skip to content

Commit d639e78

Browse files
authored
[20250805] BOJ / G5 / 수강 과목 / 김수연
1 parent 15afb29 commit d639e78

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class boj17845 {
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+
static StringBuilder sb = new StringBuilder();
11+
12+
public static void main(String[] args) throws Exception {
13+
nextLine();
14+
int N = nextInt();
15+
int K = nextInt();
16+
int[] prior = new int[K+1];
17+
int[] time = new int[K+1];
18+
int[][] bag = new int[K+1][N+1];
19+
20+
for (int i = 1; i <= K; i++) {
21+
nextLine();
22+
prior[i] = nextInt();
23+
time[i] = nextInt();
24+
}
25+
26+
for (int i = 1; i <= K; i++) {
27+
for (int j = 1; j <= N; j++) {
28+
if (time[i] <= j) bag[i][j] = Math.max(bag[i-1][j], bag[i-1][j-time[i]] + prior[i]);
29+
else bag[i][j] = bag[i-1][j];
30+
}
31+
}
32+
System.out.println(bag[K][N]);
33+
}
34+
}
35+
```

0 commit comments

Comments
 (0)