結果

問題 No.357 品物の並び替え (Middle)
ユーザー brthyyjpbrthyyjp
提出日時 2021-09-30 00:27:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 132 ms / 5,000 ms
コード長 471 bytes
コンパイル時間 445 ms
コンパイル使用メモリ 86,628 KB
実行使用メモリ 77,852 KB
最終ジャッジ日時 2023-09-23 20:42:58
合計ジャッジ時間 3,899 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
77,068 KB
testcase_01 AC 97 ms
71,568 KB
testcase_02 AC 104 ms
76,960 KB
testcase_03 AC 105 ms
76,888 KB
testcase_04 AC 112 ms
77,644 KB
testcase_05 AC 111 ms
77,668 KB
testcase_06 AC 100 ms
71,472 KB
testcase_07 AC 97 ms
71,472 KB
testcase_08 AC 113 ms
77,316 KB
testcase_09 AC 120 ms
77,852 KB
testcase_10 AC 116 ms
77,816 KB
testcase_11 AC 113 ms
77,744 KB
testcase_12 AC 132 ms
77,632 KB
testcase_13 AC 121 ms
77,456 KB
testcase_14 AC 115 ms
77,560 KB
testcase_15 AC 117 ms
77,688 KB
testcase_16 AC 118 ms
77,536 KB
testcase_17 AC 112 ms
77,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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])
0