結果

問題 No.357 品物の並び替え (Middle)
ユーザー 🍡yurahuna🍡yurahuna
提出日時 2016-04-02 15:38:16
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 533 ms / 5,000 ms
コード長 473 bytes
コンパイル時間 84 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2024-04-10 10:37:44
合計ジャッジ時間 2,947 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,752 KB
testcase_01 AC 27 ms
10,752 KB
testcase_02 AC 27 ms
10,752 KB
testcase_03 AC 28 ms
10,752 KB
testcase_04 AC 29 ms
10,752 KB
testcase_05 AC 30 ms
10,752 KB
testcase_06 AC 28 ms
10,752 KB
testcase_07 AC 26 ms
10,752 KB
testcase_08 AC 34 ms
10,752 KB
testcase_09 AC 241 ms
11,008 KB
testcase_10 AC 68 ms
10,752 KB
testcase_11 AC 66 ms
10,880 KB
testcase_12 AC 533 ms
11,392 KB
testcase_13 AC 240 ms
11,008 KB
testcase_14 AC 238 ms
11,008 KB
testcase_15 AC 67 ms
10,880 KB
testcase_16 AC 122 ms
10,752 KB
testcase_17 AC 65 ms
10,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int, input().split())
score = [[0] * n for i in range(n)]

for i in range(m):
    x, y, s = map(int, input().split())
    score[x][y] = s

dp = [0] * (1 << n)
for i in range(1 << n):
    for j in range(n):
        if (i >> j) & 1:
            continue

        nxt_score = dp[i]
        for k in range(n):
            if (i >> k) & 1:
                nxt_score += score[j][k]

        dp[i | (1 << j)] = max(dp[i | (1 << j)], nxt_score)

print(dp[(1 << n) - 1])
0