結果

問題 No.247 線形計画問題もどき
ユーザー ぴろずぴろず
提出日時 2015-07-17 22:36:51
言語 Java21
(openjdk 21)
結果
AC  
実行時間 244 ms / 2,000 ms
コード長 709 bytes
コンパイル時間 2,141 ms
コンパイル使用メモリ 73,612 KB
実行使用メモリ 111,048 KB
最終ジャッジ日時 2023-09-21 17:19:55
合計ジャッジ時間 8,264 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 190 ms
67,168 KB
testcase_01 AC 125 ms
55,872 KB
testcase_02 AC 244 ms
111,048 KB
testcase_03 AC 129 ms
55,876 KB
testcase_04 AC 130 ms
55,876 KB
testcase_05 AC 127 ms
55,684 KB
testcase_06 AC 125 ms
55,848 KB
testcase_07 AC 150 ms
57,744 KB
testcase_08 AC 144 ms
55,472 KB
testcase_09 AC 126 ms
56,004 KB
testcase_10 AC 147 ms
55,884 KB
testcase_11 AC 128 ms
56,016 KB
testcase_12 AC 128 ms
55,676 KB
testcase_13 AC 127 ms
55,852 KB
testcase_14 AC 131 ms
55,684 KB
testcase_15 AC 125 ms
55,500 KB
testcase_16 AC 135 ms
55,856 KB
testcase_17 AC 181 ms
64,560 KB
testcase_18 AC 143 ms
55,780 KB
testcase_19 AC 209 ms
85,236 KB
testcase_20 AC 219 ms
85,476 KB
testcase_21 AC 168 ms
60,300 KB
testcase_22 AC 168 ms
64,308 KB
testcase_23 AC 171 ms
60,296 KB
testcase_24 AC 217 ms
87,648 KB
testcase_25 AC 199 ms
77,712 KB
testcase_26 AC 166 ms
60,432 KB
testcase_27 AC 165 ms
64,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no247;

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

public class Main {
	public static final int INF = 1 << 29;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int c = sc.nextInt();
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i=0;i<n;i++) {
			a[i] = sc.nextInt();
		}
		int[][] dp = new int[n+1][c+1];
		for(int i=0;i<=n;i++) {
			Arrays.fill(dp[i], INF);
		}
		for(int i=0;i<=n;i++) {
			dp[i][0] = 0;
		}
		for(int i=1;i<=n;i++) {
			for(int j=0;j<=c;j++) {
				dp[i][j] = dp[i-1][j];
				if (j >= a[i-1]) {
					dp[i][j] = Math.min(dp[i][j], dp[i][j-a[i-1]] + 1);
				}
			}
		}
		System.out.println(dp[n][c] == INF ? -1 : dp[n][c]);
	}

}
0