結果

問題 No.247 線形計画問題もどき
ユーザー ynyn
提出日時 2016-08-31 22:09:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 191 ms / 2,000 ms
コード長 299 bytes
コンパイル時間 351 ms
コンパイル使用メモリ 87,232 KB
実行使用メモリ 76,760 KB
最終ジャッジ日時 2023-09-21 18:06:08
合計ジャッジ時間 4,109 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 104 ms
76,468 KB
testcase_01 AC 72 ms
75,752 KB
testcase_02 AC 191 ms
76,508 KB
testcase_03 AC 68 ms
71,260 KB
testcase_04 AC 68 ms
71,500 KB
testcase_05 AC 67 ms
71,432 KB
testcase_06 AC 67 ms
71,260 KB
testcase_07 AC 77 ms
76,632 KB
testcase_08 AC 73 ms
76,464 KB
testcase_09 AC 69 ms
71,208 KB
testcase_10 AC 73 ms
76,480 KB
testcase_11 AC 69 ms
71,400 KB
testcase_12 AC 68 ms
71,372 KB
testcase_13 AC 68 ms
71,256 KB
testcase_14 AC 69 ms
71,420 KB
testcase_15 AC 69 ms
71,480 KB
testcase_16 AC 70 ms
71,456 KB
testcase_17 AC 91 ms
75,960 KB
testcase_18 AC 74 ms
75,912 KB
testcase_19 AC 128 ms
76,372 KB
testcase_20 AC 147 ms
76,608 KB
testcase_21 AC 76 ms
75,700 KB
testcase_22 AC 82 ms
75,800 KB
testcase_23 AC 81 ms
75,960 KB
testcase_24 AC 145 ms
76,760 KB
testcase_25 AC 117 ms
76,500 KB
testcase_26 AC 85 ms
76,380 KB
testcase_27 AC 90 ms
76,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

c = int(input())
n = int(input())
a = [0] + list(map(int,input().split()))

dp = [10 ** 10] * (c + 1)
dp[0] = 0

for i in range(1, n + 1):
    for j in range(c + 1):
        if j + a[i] <= c:
            dp[j + a[i]] = min(dp[j + a[i]], dp[j] + 1)

if dp[c] >= 10 ** 10:
    dp[c] = -1
print(dp[c])
0