結果

問題 No.357 品物の並び替え (Middle)
ユーザー 👑 rin204rin204
提出日時 2022-07-05 16:26:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 92 ms / 5,000 ms
コード長 514 bytes
コンパイル時間 504 ms
コンパイル使用メモリ 86,984 KB
実行使用メモリ 77,012 KB
最終ジャッジ日時 2023-08-22 05:02:15
合計ジャッジ時間 2,639 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
75,936 KB
testcase_01 AC 61 ms
71,392 KB
testcase_02 AC 69 ms
75,864 KB
testcase_03 AC 70 ms
75,844 KB
testcase_04 AC 71 ms
76,412 KB
testcase_05 AC 70 ms
76,188 KB
testcase_06 AC 60 ms
71,176 KB
testcase_07 AC 60 ms
71,304 KB
testcase_08 AC 75 ms
76,420 KB
testcase_09 AC 83 ms
76,324 KB
testcase_10 AC 81 ms
76,524 KB
testcase_11 AC 78 ms
76,252 KB
testcase_12 AC 92 ms
77,012 KB
testcase_13 AC 89 ms
76,416 KB
testcase_14 AC 85 ms
76,376 KB
testcase_15 AC 74 ms
76,376 KB
testcase_16 AC 78 ms
76,556 KB
testcase_17 AC 76 ms
76,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int, input().split())
A = [[0] * n for _ in range(n)]
for _ in range(m):
    i, j, s = map(int, input().split())
    A[i - 1][j - 1] += s

dp = [0] * (1 << n)
for bit in range(1, 1 << n):
    bef = []
    aft = []
    for i in range(n):
        if bit >> i & 1:
            bef.append(i)
        else:
            aft.append(i)
    for j in aft:
        nbit = bit | (1 << j)
        tot = 0
        for i in bef:
            tot += A[i][j]
        dp[nbit] = max(dp[nbit], dp[bit] + tot)

print(dp[-1])
0