結果

問題 No.2317 Expression Menu
ユーザー tentententen
提出日時 2023-12-12 08:55:09
言語 Java21
(openjdk 21)
結果
AC  
実行時間 806 ms / 2,000 ms
コード長 2,480 bytes
コンパイル時間 2,683 ms
コンパイル使用メモリ 88,404 KB
実行使用メモリ 271,588 KB
最終ジャッジ日時 2023-12-12 08:55:39
合計ジャッジ時間 26,344 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
53,992 KB
testcase_01 AC 55 ms
53,984 KB
testcase_02 AC 82 ms
67,300 KB
testcase_03 AC 597 ms
271,408 KB
testcase_04 AC 533 ms
271,588 KB
testcase_05 AC 675 ms
269,556 KB
testcase_06 AC 667 ms
269,552 KB
testcase_07 AC 553 ms
271,408 KB
testcase_08 AC 609 ms
271,432 KB
testcase_09 AC 701 ms
269,644 KB
testcase_10 AC 607 ms
271,404 KB
testcase_11 AC 699 ms
271,408 KB
testcase_12 AC 655 ms
269,636 KB
testcase_13 AC 644 ms
269,528 KB
testcase_14 AC 732 ms
269,460 KB
testcase_15 AC 664 ms
269,636 KB
testcase_16 AC 727 ms
269,632 KB
testcase_17 AC 608 ms
271,588 KB
testcase_18 AC 660 ms
271,572 KB
testcase_19 AC 698 ms
269,560 KB
testcase_20 AC 769 ms
269,460 KB
testcase_21 AC 652 ms
269,636 KB
testcase_22 AC 593 ms
269,464 KB
testcase_23 AC 737 ms
269,660 KB
testcase_24 AC 772 ms
269,640 KB
testcase_25 AC 739 ms
269,656 KB
testcase_26 AC 806 ms
269,652 KB
testcase_27 AC 751 ms
269,824 KB
testcase_28 AC 679 ms
269,644 KB
testcase_29 AC 799 ms
269,644 KB
testcase_30 AC 716 ms
269,648 KB
testcase_31 AC 706 ms
269,648 KB
testcase_32 AC 726 ms
269,644 KB
testcase_33 AC 54 ms
53,988 KB
testcase_34 AC 53 ms
53,968 KB
testcase_35 AC 55 ms
53,988 KB
testcase_36 AC 57 ms
53,972 KB
testcase_37 AC 53 ms
53,984 KB
testcase_38 AC 331 ms
269,340 KB
testcase_39 AC 323 ms
269,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    static int[] sizes;
    static int[] amounts;
    static int[] values;
    static long[][][] dp;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int menu = sc.nextInt();
        int weight = sc.nextInt();
        sizes = new int[n];
        amounts = new int[n];
        values = new int[n];
        for (int i = 0; i < n; i++) {
            sizes[i] = sc.nextInt();
            amounts[i] = sc.nextInt();
            values[i] = sc.nextInt();
        }
        dp = new long[n][menu + 1][weight + 1];
        for (long[][] arr1 : dp) {
            for (long[] arr2 : arr1) {
                Arrays.fill(arr2, -1);
            }
        }
        System.out.println(dfw(n - 1, menu, weight));
    }
    
    static long dfw(int idx, int v, int w) {
        if (v < 0 || w < 0) {
            return Long.MIN_VALUE;
        }
        if (idx < 0) {
            return 0;
        }
        if (dp[idx][v][w] < 0) {
            dp[idx][v][w] = Math.max(dfw(idx - 1, v, w), dfw(idx - 1, v - sizes[idx], w - amounts[idx]) + values[idx]);
        }
        return dp[idx][v][w];
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0