結果

問題 No.247 線形計画問題もどき
ユーザー yuki2006yuki2006
提出日時 2015-07-15 17:16:48
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 906 bytes
コンパイル時間 5,359 ms
コンパイル使用メモリ 72,776 KB
実行使用メモリ 58,036 KB
最終ジャッジ日時 2023-09-22 16:33:09
合計ジャッジ時間 9,665 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 119 ms
55,844 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 120 ms
55,724 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 117 ms
39,956 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 142 ms
39,916 KB
testcase_22 WA -
testcase_23 AC 141 ms
39,836 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 135 ms
39,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Yuki_678 {

    public Yuki_678() {
        Scanner scanner = new Scanner(System.in);
        int A = scanner.nextInt();

        int N = scanner.nextInt();
        int[] data = new int[N];
        for (int i = 0; i < N; i++) {
            data[i] = scanner.nextInt();
        }

        int[] dp = new int[100000 + 1];
        dp[0] = 0;
        for (int i = 0; i <= A; i++) {
            for (int j = 0; j < N; j++) {
                int k = i - data[j];
                if (k >= 0) {
                    dp[i] = Math.min(dp[i], dp[k] + 1);
                }
            }
        }
        if (dp[A] == 0) {
            System.out.println(-1);
        } else {
            System.out.println(dp[A]);
        }
    }

    public static void main(String[] args) {
        Yuki_678 hoge = new Yuki_678();
    }
}
0