結果
| 問題 | No.247 線形計画問題もどき |
| コンテスト | |
| ユーザー |
kou6839
|
| 提出日時 | 2015-07-20 13:57:11 |
| 言語 | Java (openjdk 25.0.2) |
| 結果 |
AC
|
| 実行時間 | 98 ms / 2,000 ms |
| コード長 | 578 bytes |
| 記録 | |
| コンパイル時間 | 1,701 ms |
| コンパイル使用メモリ | 81,428 KB |
| 実行使用メモリ | 49,224 KB |
| 最終ジャッジ日時 | 2026-03-29 01:34:16 |
| 合計ジャッジ時間 | 4,310 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 23 |
ソースコード
import java.util.*;
public class Main {
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[C+1];
Arrays.fill(dp, Integer.MAX_VALUE);
dp[0]=0;
for(int i=1;i<=C;i++){
for(int j=0;j<N;j++){
if(i-a[j]<0 || dp[i-a[j]]==Integer.MAX_VALUE) continue;
dp[i]=Math.min(dp[i],dp[i-a[j]]+1);
}
}
if(dp[C]==Integer.MAX_VALUE){
System.out.println(-1);
}else{
System.out.println(dp[C]);
}
}
}
kou6839