結果

問題 No.286 Modulo Discount Store
ユーザー Tawara
提出日時 2015-10-13 21:50:29
言語 Python2
(2.7.18)
結果
AC  
実行時間 291 ms / 2,000 ms
コード長 391 bytes
コンパイル時間 33 ms
コンパイル使用メモリ 6,912 KB
実行使用メモリ 12,572 KB
最終ジャッジ日時 2024-07-21 07:35:04
合計ジャッジ時間 2,335 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

N = input()
M = [input() for i in xrange(N)]
total = {0:0}
dp = {0:0}
for i in xrange(N):
	tmp_dp = dict()
	for k,v in dp.iteritems():
		for j in xrange(N):
			jbit = 1 << j
			if (jbit & k) != 0:
				continue
			nk = k|jbit
			total[nk] = total[k] + M[j]
			nv = v + max(0,M[j] - total[k]%1000)
			if not(nk in tmp_dp and nv >= tmp_dp[nk]):
				tmp_dp[nk] = nv
	dp = tmp_dp
print dp[2**N-1]
0