結果

問題 No.90 品物の並び替え
ユーザー irumo8202irumo8202
提出日時 2022-01-21 18:21:23
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 28 ms / 5,000 ms
コード長 530 bytes
コンパイル時間 180 ms
コンパイル使用メモリ 10,844 KB
実行使用メモリ 8,652 KB
最終ジャッジ日時 2023-08-17 01:05:25
合計ジャッジ時間 1,155 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,616 KB
testcase_01 AC 24 ms
8,612 KB
testcase_02 AC 19 ms
8,652 KB
testcase_03 AC 20 ms
8,492 KB
testcase_04 AC 20 ms
8,648 KB
testcase_05 AC 22 ms
8,544 KB
testcase_06 AC 23 ms
8,612 KB
testcase_07 AC 20 ms
8,552 KB
testcase_08 AC 19 ms
8,492 KB
testcase_09 AC 28 ms
8,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

N, M = map(int, input().split())

G = defaultdict(dict)
for _ in range(M):
    u, v, score = map(int, input().split())
    G[v][u] = score

dp = [0] * (1 << N)

for bit in range(1 << N):
    for u in range(N):
        if bit >> u & 1:
            continue
        tot = 0
        for v in range(N):
            if ~bit >> v & 1:
                continue
            if v in G[u]:
                tot += G[u][v]
        dp[bit | (1 << u)] = max(dp[bit | (1 << u)], dp[bit] + tot)

print(dp[-1])
0