結果

問題 No.617 Nafmo、買い出しに行く
ユーザー aaaaasatoriaaaaasatori
提出日時 2018-02-14 08:32:25
言語 Java21
(openjdk 21)
結果
AC  
実行時間 489 ms / 2,000 ms
コード長 715 bytes
コンパイル時間 6,786 ms
コンパイル使用メモリ 72,252 KB
実行使用メモリ 370,960 KB
最終ジャッジ日時 2023-08-22 18:41:12
合計ジャッジ時間 12,378 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 312 ms
368,328 KB
testcase_01 AC 285 ms
368,256 KB
testcase_02 AC 317 ms
368,332 KB
testcase_03 AC 356 ms
368,700 KB
testcase_04 AC 298 ms
369,224 KB
testcase_05 AC 372 ms
368,788 KB
testcase_06 AC 489 ms
368,664 KB
testcase_07 AC 484 ms
370,632 KB
testcase_08 AC 279 ms
370,664 KB
testcase_09 AC 276 ms
370,504 KB
testcase_10 AC 426 ms
370,536 KB
testcase_11 AC 435 ms
368,992 KB
testcase_12 AC 379 ms
370,648 KB
testcase_13 AC 347 ms
370,204 KB
testcase_14 AC 368 ms
370,424 KB
testcase_15 AC 284 ms
370,576 KB
testcase_16 AC 293 ms
370,648 KB
testcase_17 AC 279 ms
370,292 KB
testcase_18 AC 274 ms
370,740 KB
testcase_19 AC 275 ms
370,960 KB
testcase_20 AC 271 ms
370,840 KB
testcase_21 AC 272 ms
370,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class No617 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(); // 荷物の個数
		int K = sc.nextInt(); // 持てる重さの最大値
		int weight[] = new int[30]; //各荷物の重さ(=価値)
		int dp[][] = new int[30][2000010];
		for(int i = 0;i < N;i++) {
			weight[i] = sc.nextInt();
		}
		//初期化 入力
		
		for(int i = 0;i <= K;i++) {
			dp[0][i] = 0;
		}
		
		for(int i = 0;i < N;i++) {
			for(int j = 0;j <= K;j++) {
				if(j >= weight[i]) {
					dp[i+1][j] = Math.max(dp[i][j - weight[i]] + weight[i],dp[i][j]);
				}else {
					dp[i+1][j] = dp[i][j];
				}
			}
		}
		
		System.out.println(dp[N][K]);
	}
}
0