結果
問題 |
No.357 品物の並び替え (Middle)
|
ユーザー |
|
提出日時 | 2019-10-29 12:37:59 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 102 ms / 5,000 ms |
コード長 | 656 bytes |
コンパイル時間 | 848 ms |
コンパイル使用メモリ | 81,792 KB |
実行使用メモリ | 76,160 KB |
最終ジャッジ日時 | 2024-09-14 21:27:11 |
合計ジャッジ時間 | 2,986 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 |
ソースコード
def rec(S): if memo[S] != -1: return memo[S] if S == (1<<N)-1: memo[S] = 0 return 0 res = 0 for n in range(N): if not (S>>n)&1: add = 0 for prev, score in scores[n]: if (S>>prev)&1: add += score res = max(res, rec(S|(1<<n))+add) memo[S] = res return res N, M = map(int, input().split()) scores = [[] for _ in range(N)] for _ in range(M): item1, item2, score = map(int, input().split()) scores[item2].append((item1, score)) memo = [-1] * (1<<N) print(rec(0))