結果

問題 No.2093 Shio Ramen
ユーザー tentententen
提出日時 2022-10-11 09:40:49
言語 Java21
(openjdk 21)
結果
AC  
実行時間 115 ms / 2,000 ms
コード長 1,700 bytes
コンパイル時間 4,647 ms
コンパイル使用メモリ 74,208 KB
実行使用メモリ 57,400 KB
最終ジャッジ日時 2023-09-07 11:17:51
合計ジャッジ時間 8,065 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
49,344 KB
testcase_01 AC 45 ms
49,160 KB
testcase_02 AC 45 ms
49,256 KB
testcase_03 AC 47 ms
49,460 KB
testcase_04 AC 46 ms
49,116 KB
testcase_05 AC 46 ms
49,392 KB
testcase_06 AC 46 ms
49,100 KB
testcase_07 AC 46 ms
49,172 KB
testcase_08 AC 44 ms
49,312 KB
testcase_09 AC 74 ms
51,316 KB
testcase_10 AC 105 ms
54,288 KB
testcase_11 AC 51 ms
49,372 KB
testcase_12 AC 77 ms
52,424 KB
testcase_13 AC 83 ms
52,472 KB
testcase_14 AC 78 ms
52,508 KB
testcase_15 AC 99 ms
54,736 KB
testcase_16 AC 68 ms
51,660 KB
testcase_17 AC 82 ms
52,512 KB
testcase_18 AC 113 ms
57,120 KB
testcase_19 AC 103 ms
54,932 KB
testcase_20 AC 97 ms
52,612 KB
testcase_21 AC 100 ms
54,612 KB
testcase_22 AC 99 ms
54,152 KB
testcase_23 AC 109 ms
56,884 KB
testcase_24 AC 109 ms
56,756 KB
testcase_25 AC 115 ms
54,884 KB
testcase_26 AC 111 ms
56,972 KB
testcase_27 AC 110 ms
57,300 KB
testcase_28 AC 114 ms
57,120 KB
testcase_29 AC 111 ms
57,296 KB
testcase_30 AC 110 ms
57,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static int[] solts;
    static int[] values;
    static int[][] dp;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int x = sc.nextInt();
        solts = new int[n];
        values = new int[n];
        for (int i = 0; i < n; i++) {
            solts[i] = sc.nextInt();
            values[i] = sc.nextInt();
        }
        dp = new int[n][x + 1];
        for (int[] arr : dp) {
            Arrays.fill(arr, -1);
        }
        System.out.println(dfw(n - 1, x));
    }
    
    static int dfw(int idx, int v) {
        if (v < 0) {
            return Integer.MIN_VALUE;
        }
        if (idx < 0) {
            return 0;
        }
        if (dp[idx][v] < 0)  {
            dp[idx][v] = Math.max(dfw(idx - 1, v), dfw(idx - 1, v - solts[idx]) + values[idx]);
        }
        return dp[idx][v];
    }
}
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 String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0