File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
Expand file tree Collapse file tree 1 file changed +33
-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 boj1106 {
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 C = nextInt();
14+ int N = nextInt();
15+ int [] dp = new int [C + 100 ];
16+ int answer = Integer . MAX_VALUE ;
17+ Arrays . fill(dp, Integer . MAX_VALUE );
18+ dp[0 ] = 0 ;
19+ for (int i = 0 ; i < N ; i++ ) {
20+ nextLine();
21+ int cost = nextInt();
22+ int num = nextInt();
23+ for (int j = num; j < C + 100 ; j++ ) {
24+ if (dp[j - num] != Integer . MAX_VALUE ) {
25+ dp[j] = Math . min(dp[j], dp[j- num] + cost);
26+ }
27+ }
28+ }
29+ for (int i = C ; i < C + 100 ; i++ ) answer = Math . min(answer, dp[i]);
30+ System . out. println(answer);
31+ }
32+ }
33+ ```
You can’t perform that action at this time.
0 commit comments