File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments