結果

問題 No.247 線形計画問題もどき
ユーザー TawaraTawara
提出日時 2015-07-18 01:00:26
言語 PyPy2
(7.3.15)
結果
WA  
実行時間 -
コード長 364 bytes
コンパイル時間 1,238 ms
コンパイル使用メモリ 77,796 KB
実行使用メモリ 79,692 KB
最終ジャッジ日時 2023-09-22 18:47:36
合計ジャッジ時間 4,232 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 74 ms
76,420 KB
testcase_02 AC 73 ms
76,092 KB
testcase_03 AC 73 ms
76,540 KB
testcase_04 AC 72 ms
76,564 KB
testcase_05 AC 73 ms
76,264 KB
testcase_06 AC 73 ms
76,096 KB
testcase_07 AC 74 ms
76,540 KB
testcase_08 AC 73 ms
76,604 KB
testcase_09 AC 73 ms
76,280 KB
testcase_10 AC 72 ms
76,504 KB
testcase_11 AC 74 ms
76,504 KB
testcase_12 AC 72 ms
76,564 KB
testcase_13 AC 75 ms
76,340 KB
testcase_14 AC 73 ms
76,340 KB
testcase_15 AC 73 ms
76,384 KB
testcase_16 AC 72 ms
76,516 KB
testcase_17 WA -
testcase_18 AC 72 ms
76,396 KB
testcase_19 AC 102 ms
78,796 KB
testcase_20 WA -
testcase_21 AC 73 ms
76,336 KB
testcase_22 WA -
testcase_23 AC 72 ms
76,380 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 72 ms
76,512 KB
testcase_27 AC 78 ms
78,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def dfs(C,S,idx):
	if idx == N:
		if C == 0:
			return S
		else:
			return None
	ret = None
	for i in range(C/a[idx],-1,-1):
		ret = dfs(C-a[idx]*i,S+i,idx+1)
		if ret is not None:
			break
	return ret

C = int(raw_input())
N = int(raw_input())
a = map(int,raw_input().split(" "))
a.sort(reverse = True)
ans = dfs(C,0,0)
if ans is None:
	print -1
else:
	print ans
0