結果

問題 No.357 品物の並び替え (Middle)
ユーザー lloyzlloyz
提出日時 2023-10-31 00:34:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 80 ms / 5,000 ms
コード長 505 bytes
コンパイル時間 193 ms
コンパイル使用メモリ 81,852 KB
実行使用メモリ 70,624 KB
最終ジャッジ日時 2023-10-31 00:34:44
合計ジャッジ時間 2,370 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
64,380 KB
testcase_01 AC 41 ms
53,492 KB
testcase_02 AC 46 ms
61,588 KB
testcase_03 AC 47 ms
61,592 KB
testcase_04 AC 53 ms
64,228 KB
testcase_05 AC 54 ms
64,220 KB
testcase_06 AC 42 ms
55,540 KB
testcase_07 AC 42 ms
55,540 KB
testcase_08 AC 57 ms
66,300 KB
testcase_09 AC 66 ms
68,540 KB
testcase_10 AC 59 ms
66,460 KB
testcase_11 AC 67 ms
70,624 KB
testcase_12 AC 80 ms
70,576 KB
testcase_13 AC 69 ms
68,504 KB
testcase_14 AC 62 ms
66,436 KB
testcase_15 AC 59 ms
68,524 KB
testcase_16 AC 60 ms
66,456 KB
testcase_17 AC 62 ms
68,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

n, m = map(int, input().split())
G = defaultdict(list)
for _ in range(m):
    a, b, p = map(int, input().split())
    G[a].append((b, p))
DP = [-1 for _ in range(1 << n)]
DP[0] = 0
for bit in range(1 << n):
    for i in range(n):
        res = 0
        if (bit >> i) & 1:
            continue
        for j, p in G[i]:
            if (bit >> j) & 1:
                res += p
        nbit = bit | (1 << i)
        DP[nbit] = max(DP[nbit], DP[bit] + res)
print(DP[-1])
0