結果

問題 No.357 品物の並び替え (Middle)
ユーザー rlangevinrlangevin
提出日時 2023-01-08 18:26:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 103 ms / 5,000 ms
コード長 450 bytes
コンパイル時間 482 ms
コンパイル使用メモリ 87,308 KB
実行使用メモリ 76,800 KB
最終ジャッジ日時 2023-08-22 04:05:42
合計ジャッジ時間 3,103 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
76,028 KB
testcase_01 AC 70 ms
71,508 KB
testcase_02 AC 73 ms
75,812 KB
testcase_03 AC 75 ms
75,820 KB
testcase_04 AC 80 ms
76,372 KB
testcase_05 AC 81 ms
76,544 KB
testcase_06 AC 70 ms
71,284 KB
testcase_07 AC 68 ms
71,064 KB
testcase_08 AC 81 ms
76,472 KB
testcase_09 AC 88 ms
76,536 KB
testcase_10 AC 88 ms
76,576 KB
testcase_11 AC 85 ms
76,412 KB
testcase_12 AC 103 ms
76,408 KB
testcase_13 AC 90 ms
76,136 KB
testcase_14 AC 88 ms
76,228 KB
testcase_15 AC 90 ms
76,800 KB
testcase_16 AC 87 ms
76,468 KB
testcase_17 AC 84 ms
76,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M = map(int, input().split())
G = [[] for i in range(N)]
for i in range(M):
    A, B, C = map(int, input().split())
    G[B].append((A, C))
    
dp = [-10 ** 18] * (1 << N)
dp[0] = 0
for i in range(1 << N):
    for j in range(N):
        cnt = 0
        if (i >> j) & 1:
            continue
        for u, c in G[j]:
            if (i >> u) & 1:
                cnt += c
        dp[i | (1 << j)] = max(dp[i | (1 << j)], dp[i] + cnt)
print(dp[-1])
0