-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCO060715-src.cpp
56 lines (49 loc) · 1.4 KB
/
CO060715-src.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.util.Scanner;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Cuong Nguyen
*/
public class Main {
public static int MAX = 200;
public static int CMAX = 1000;
public static int INF = Integer.MAX_VALUE / 2;
public static int n, weight, res, sum;
public static int f[][] = new int [MAX][CMAX];
public static int w[] = new int [MAX];
public static int c[] = new int [MAX];
static void Init() {
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= weight; j++) {
f[i][j] = 0;
}
}
}
static void process() {
Init();
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= weight; j++) {
f[i][j] = f[i - 1][j];
if (w[i] <= j) {
f[i][j] = Math.max(f[i][j], f[i - 1][j - w[i]] + c[i]);
}
}
}
System.out.println(f[n][weight]);
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
n = in.nextInt();
weight = in.nextInt();
sum = 0;
for (int i = 1; i <= n; i++) {
w[i] = in.nextInt();
c[i] = in.nextInt();
}
process();
}
}