結果

問題 No.357 品物の並び替え (Middle)
ユーザー neterukunneterukun
提出日時 2019-10-22 20:33:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 103 ms / 5,000 ms
コード長 526 bytes
コンパイル時間 965 ms
コンパイル使用メモリ 86,740 KB
実行使用メモリ 76,556 KB
最終ジャッジ日時 2023-09-18 00:54:43
合計ジャッジ時間 3,389 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
76,292 KB
testcase_01 AC 71 ms
71,032 KB
testcase_02 AC 77 ms
76,428 KB
testcase_03 AC 82 ms
76,120 KB
testcase_04 AC 81 ms
76,312 KB
testcase_05 AC 80 ms
76,232 KB
testcase_06 AC 73 ms
75,828 KB
testcase_07 AC 70 ms
71,364 KB
testcase_08 AC 89 ms
76,460 KB
testcase_09 AC 102 ms
76,352 KB
testcase_10 AC 90 ms
76,436 KB
testcase_11 AC 87 ms
76,460 KB
testcase_12 AC 103 ms
76,264 KB
testcase_13 AC 102 ms
76,556 KB
testcase_14 AC 102 ms
76,188 KB
testcase_15 AC 95 ms
76,176 KB
testcase_16 AC 93 ms
76,476 KB
testcase_17 AC 90 ms
76,540 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int, input().split())
info = [list(map(int, input().split())) for i in range(m)]

p = [[0]*n for i in range(n)]
for i in range(m):
    a, b, cost = info[i]
    p[a][b] = cost

dp = [0]*(1 << n)
for bit_state in range(1 << n):
    for i in range(n):
        if (bit_state >> i) & 1:
            continue
        score = 0
        for j in range(n):
            if (bit_state >> j) & 1:
                score += p[j][i]
        dp[bit_state|(1 << i)] = max(dp[bit_state|(1 << i)], dp[bit_state] + score)
print(dp[-1])
0