File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed
Expand file tree Collapse file tree 1 file changed +48
-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 boj4781 {
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 double nextDouble() { return Double . parseDouble(st. nextToken()); }
11+
12+ public static void main(String [] args) throws Exception {
13+ while (true ) {
14+ nextLine();
15+ int n = nextInt(); // 사탕 종류의 수
16+ int m = (int ) (nextDouble() * 100 ); // 상근이 돈 양
17+ if (n == 0 && m == 0 ) break ;
18+ Candy [] candy = new Candy [n+ 1 ];
19+ for (int i = 1 ; i <= n; i++ ) {
20+ nextLine();
21+ candy[i] = new Candy (nextInt(), (int ) (nextDouble() * 100 + 0.5 ));
22+ }
23+ System . out. println(solve(n, m, candy));
24+ }
25+ }
26+
27+ static private int solve(int n, int m, Candy [] candy) {
28+ int [] dp = new int [m+ 1 ];
29+ for (int i = 1 ; i <= n; i++ ) { // 사탕 종류
30+ int cal = candy[i]. c;
31+ int val = candy[i]. p;
32+ for (int j = 0 ; j <= m; j++ ) {
33+ if (j - val >= 0 ) dp[j] = Math . max(dp[j], dp[j- val] + cal);
34+ }
35+ }
36+ return dp[m];
37+ }
38+
39+ static class Candy {
40+ int c;
41+ int p;
42+ public Candy (int c , int p ) {
43+ this . c = c;
44+ this . p = p;
45+ }
46+ }
47+ }
48+ ```
You can’t perform that action at this time.
0 commit comments