結果

問題 No.90 品物の並び替え
コンテスト
ユーザー Tawara
提出日時 2015-09-15 00:20:20
言語 PyPy2
(7.3.20)
コンパイル:
pypy2 -m py_compile _filename_
実行:
/usr/bin/pypy2 Main.pyc
結果
AC  
実行時間 87 ms / 5,000 ms
+ 83µs
コード長 406 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 70 ms
コンパイル使用メモリ 81,408 KB
実行使用メモリ 84,096 KB
最終ジャッジ日時 2026-07-17 21:14:46
合計ジャッジ時間 1,903 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

N,M=map(int,raw_input().split())
S = [map(int,raw_input().split()) for i in xrange(M)]
dp = {0:0}
for i in xrange(N):
	tmp_dp = dict()
	for k,v in dp.iteritems():
		for j in xrange(N):
			bit = 1<<j
			if k&bit: continue
			nk = k|bit
			tmp_v = v + sum(s[2] for s in S if s[0]==j and ((1<<s[1])&nk)==0)
			if not (nk in tmp_dp and tmp_dp[nk] >= tmp_v):
				tmp_dp[nk] = tmp_v
	dp = tmp_dp
print dp[2**N-1]
0