結果

問題 No.2317 Expression Menu
ユーザー tentententen
提出日時 2023-05-30 09:51:48
言語 Java21
(openjdk 21)
結果
AC  
実行時間 802 ms / 2,000 ms
コード長 2,452 bytes
コンパイル時間 2,840 ms
コンパイル使用メモリ 86,092 KB
実行使用メモリ 267,864 KB
最終ジャッジ日時 2023-08-28 00:27:45
合計ジャッジ時間 26,025 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,460 KB
testcase_01 AC 42 ms
49,452 KB
testcase_02 AC 76 ms
63,448 KB
testcase_03 AC 595 ms
267,216 KB
testcase_04 AC 542 ms
267,156 KB
testcase_05 AC 685 ms
267,520 KB
testcase_06 AC 644 ms
267,368 KB
testcase_07 AC 544 ms
267,120 KB
testcase_08 AC 562 ms
267,168 KB
testcase_09 AC 690 ms
267,400 KB
testcase_10 AC 568 ms
266,932 KB
testcase_11 AC 696 ms
267,272 KB
testcase_12 AC 623 ms
267,380 KB
testcase_13 AC 634 ms
267,304 KB
testcase_14 AC 714 ms
267,024 KB
testcase_15 AC 639 ms
267,652 KB
testcase_16 AC 744 ms
267,864 KB
testcase_17 AC 594 ms
267,488 KB
testcase_18 AC 658 ms
267,428 KB
testcase_19 AC 678 ms
267,400 KB
testcase_20 AC 767 ms
266,644 KB
testcase_21 AC 628 ms
267,464 KB
testcase_22 AC 595 ms
267,132 KB
testcase_23 AC 724 ms
267,304 KB
testcase_24 AC 749 ms
267,552 KB
testcase_25 AC 709 ms
267,284 KB
testcase_26 AC 802 ms
267,280 KB
testcase_27 AC 731 ms
267,600 KB
testcase_28 AC 708 ms
267,284 KB
testcase_29 AC 786 ms
267,496 KB
testcase_30 AC 717 ms
265,496 KB
testcase_31 AC 679 ms
266,880 KB
testcase_32 AC 723 ms
267,352 KB
testcase_33 AC 44 ms
49,452 KB
testcase_34 AC 44 ms
49,440 KB
testcase_35 AC 46 ms
49,320 KB
testcase_36 AC 44 ms
49,396 KB
testcase_37 AC 44 ms
49,304 KB
testcase_38 AC 325 ms
267,076 KB
testcase_39 AC 320 ms
267,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static int[] menu;
    static int[] volume;
    static int[] values;
    static long[][][] dp;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        menu = new int[n];
        volume = new int[n];
        values = new int[n];
        for (int i = 0; i < n; i++) {
            menu[i] = sc.nextInt();
            volume[i] = sc.nextInt();
            values[i] = sc.nextInt();
        }
        dp = new long[n][x + 1][y + 1];
        for (long[][] arr1 : dp) {
            for (long[] arr2 : arr1) {
                Arrays.fill(arr2, -1);
            }
        }
        System.out.println(dfw(n - 1, x, y));
    }
    
    static long dfw(int idx, int v, int w) {
        if (v < 0 || w < 0) {
            return Integer.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 - menu[idx], w - volume[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