結果

問題 No.247 線形計画問題もどき
ユーザー Tawara
提出日時 2015-07-18 01:00:26
言語 PyPy2
(7.3.15)
結果
WA  
実行時間 -
コード長 364 bytes
コンパイル時間 2,209 ms
コンパイル使用メモリ 76,160 KB
実行使用メモリ 77,696 KB
最終ジャッジ日時 2024-07-08 10:00:33
合計ジャッジ時間 4,167 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 17 WA * 6
権限があれば一括ダウンロードができます

ソースコード

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