제출 #645887

#제출 시각아이디문제언어결과실행 시간메모리
645887ateacodeKnapsack (NOI18_knapsack)Java
0 / 100
135 ms12256 KiB
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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...