結果
問題 | No.357 品物の並び替え (Middle) |
ユーザー |
![]() |
提出日時 | 2021-09-30 00:27:59 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 73 ms / 5,000 ms |
コード長 | 471 bytes |
コンパイル時間 | 425 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 70,912 KB |
最終ジャッジ日時 | 2024-07-16 20:34:29 |
合計ジャッジ時間 | 2,149 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 |
ソースコード
n, m = map(int, input().split()) from collections import defaultdict d = defaultdict(lambda: []) for i in range(m): a, b, c = map(int, input().split()) d[b].append((a, c)) INF = 10**18 dp = [-INF]*(1<<n) dp[0] = 0 for s in range(1<<n): for i in range(n): if (s>>i)&1: continue ns = s|(1<<i) x = 0 for j, c in d[i]: if (s>>j)&1: x += c dp[ns] = max(dp[ns], dp[s]+x) print(dp[-1])