結果
| 問題 |
No.90 品物の並び替え
|
| コンテスト | |
| ユーザー |
Tawara
|
| 提出日時 | 2015-09-15 00:20:20 |
| 言語 | Python2 (2.7.18) |
| 結果 |
AC
|
| 実行時間 | 19 ms / 5,000 ms |
| コード長 | 406 bytes |
| コンパイル時間 | 44 ms |
| コンパイル使用メモリ | 6,912 KB |
| 実行使用メモリ | 6,272 KB |
| 最終ジャッジ日時 | 2024-07-19 06:32:47 |
| 合計ジャッジ時間 | 627 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 9 |
ソースコード
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]
Tawara