이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
import java.util.Arrays;
import java.util.Scanner;
class DayOne {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int maxWeight = in.nextInt();
int numItems = in.nextInt();
int[] values = new int[numItems];
int[] weights = new int[numItems];
int[] quantities = new int[numItems];
for(int i = 0; i < numItems; ++i) {
values[i] = in.nextInt();
weights[i] = in.nextInt();
quantities[i] = in.nextInt();
}
int[] maxValueGivenWeight = new int[maxWeight + 1];
for(int i = 0; i < numItems; ++i) {
for(int q = 0; q < quantities[i]; ++q) {
// consider the subset of items from 0..i
for(int curWeight = maxWeight; curWeight >= 0; --curWeight) {
if(weights[i] <= curWeight) {
maxValueGivenWeight[curWeight] = Math.max(
maxValueGivenWeight[curWeight],
values[i] + maxValueGivenWeight[curWeight - weights[i]]
);
}
}
}
}
System.out.println(maxValueGivenWeight[maxWeight]);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |