結果
| 問題 |
No.5 数字のブロック
|
| ユーザー |
uafr_cs
|
| 提出日時 | 2015-04-30 03:49:40 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 387 ms / 5,000 ms |
| コード長 | 714 bytes |
| コンパイル時間 | 1,883 ms |
| コンパイル使用メモリ | 74,312 KB |
| 実行使用メモリ | 58,720 KB |
| 最終ジャッジ日時 | 2024-11-17 22:41:10 |
| 合計ジャッジ時間 | 10,290 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 34 |
ソースコード
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
final int L = sc.nextInt();
final int N = sc.nextInt();
int[] ws = new int[N];
for(int i = 0; i < N; i++){
ws[i] = sc.nextInt();
}
int[] DP = new int[L + 1];
Arrays.fill(DP, -1);
DP[0] = 0;
int max = Integer.MIN_VALUE;
for(final int weight : ws){
for(int current = L - weight; current >= 0; current--){
if(DP[current] < 0){
continue;
}
DP[weight + current] = Math.max(DP[weight + current], DP[current] + 1);
max = Math.max(max, DP[weight + current]);
}
}
System.out.println(max);
}
}
uafr_cs