結果

問題 No.247 線形計画問題もどき
ユーザー TawaraTawara
提出日時 2015-07-19 00:07:13
言語 Python2
(2.7.18)
結果
AC  
実行時間 939 ms / 2,000 ms
コード長 323 bytes
コンパイル時間 966 ms
コンパイル使用メモリ 6,528 KB
実行使用メモリ 12,056 KB
最終ジャッジ日時 2023-09-21 17:27:23
合計ジャッジ時間 6,476 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 238 ms
8,048 KB
testcase_01 AC 12 ms
5,892 KB
testcase_02 AC 101 ms
12,008 KB
testcase_03 AC 12 ms
5,896 KB
testcase_04 AC 12 ms
5,864 KB
testcase_05 AC 11 ms
5,944 KB
testcase_06 AC 11 ms
5,836 KB
testcase_07 AC 106 ms
9,728 KB
testcase_08 AC 91 ms
12,056 KB
testcase_09 AC 11 ms
5,840 KB
testcase_10 AC 57 ms
9,808 KB
testcase_11 AC 11 ms
6,016 KB
testcase_12 AC 12 ms
5,920 KB
testcase_13 AC 12 ms
5,988 KB
testcase_14 AC 12 ms
5,944 KB
testcase_15 AC 11 ms
5,964 KB
testcase_16 AC 12 ms
5,948 KB
testcase_17 AC 141 ms
7,464 KB
testcase_18 AC 41 ms
6,432 KB
testcase_19 AC 511 ms
8,564 KB
testcase_20 AC 849 ms
8,972 KB
testcase_21 AC 23 ms
6,288 KB
testcase_22 AC 68 ms
6,572 KB
testcase_23 AC 30 ms
6,340 KB
testcase_24 AC 939 ms
9,752 KB
testcase_25 AC 581 ms
8,576 KB
testcase_26 AC 130 ms
8,096 KB
testcase_27 AC 129 ms
7,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

C = int(raw_input())
N = int(raw_input())
a = sorted(list(set(map(int,raw_input().split(" ")))))
M = len(a)
UB = 10**5+1
dp = [UB for i in range(C+1)]
dp[0] = 0
for i in range(1,C+1):
	for j in range(M):
		if a[j] > i: 
			break
		if dp[i-a[j]] + 1 < dp[i]: 
			dp[i] = dp[i-a[j]] + 1
			
print -1 if dp[C] == UB else dp[C]
0