結果

問題 No.90 品物の並び替え
ユーザー halshiphalship
提出日時 2021-06-28 21:18:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 22 ms / 5,000 ms
コード長 532 bytes
コンパイル時間 76 ms
コンパイル使用メモリ 10,900 KB
実行使用メモリ 7,976 KB
最終ジャッジ日時 2023-09-07 22:19:20
合計ジャッジ時間 880 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,880 KB
testcase_01 AC 18 ms
7,844 KB
testcase_02 AC 15 ms
7,780 KB
testcase_03 AC 17 ms
7,948 KB
testcase_04 AC 17 ms
7,940 KB
testcase_05 AC 18 ms
7,956 KB
testcase_06 AC 18 ms
7,976 KB
testcase_07 AC 16 ms
7,948 KB
testcase_08 AC 16 ms
7,956 KB
testcase_09 AC 22 ms
7,860 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = [int(s) for s in input().split()]
table = [[0 for _ in range(n)] for _ in range(n)]

for i in range(m):
    item1, item2, score = map(int, input().split())
    table[item1][item2] = score

dp = [0] * (1 << n)

for x in range(0, 1 << n):
    for i in range(n):
        if x & (1 << i):
            continue

        score = dp[x]
        for j in range(n):
            if x & (1 << j):
                score += table[j][i]

        v = x | (1 << i)
        if dp[v] < score:
            dp[v] = score

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