結果
問題 |
No.90 品物の並び替え
|
ユーザー |
![]() |
提出日時 | 2021-11-20 14:34:34 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 32 ms / 5,000 ms |
コード長 | 711 bytes |
コンパイル時間 | 73 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 10,880 KB |
最終ジャッジ日時 | 2024-06-11 15:40:43 |
合計ジャッジ時間 | 966 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 9 |
ソースコード
from collections import defaultdict N, M = map(int, input().split()) graph = defaultdict(dict) for _ in range(M): u, v, score = map(int, input().split()) graph[v][u] = score # print(graph) dp = [0] * (1 << N) for S in range(1 << N): for u in range(N): # すでにuがSに含まれていたらskip if S & (1 << u): continue # print(bin(S)[2:], u) score = 0 for v in range(N): if not (S & (1 << v)): continue if v in graph[u]: # print(u, v) score += graph[u][v] # print(' score:', score) dp[S ^ (1 << u)] = max(dp[S ^ (1 << u)], dp[S] + score) print(dp[-1])