結果

問題 No.90 品物の並び替え
ユーザー nisizawanisizawa
提出日時 2017-12-11 09:03:33
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 23 ms / 5,000 ms
コード長 526 bytes
コンパイル時間 82 ms
コンパイル使用メモリ 10,900 KB
実行使用メモリ 7,944 KB
最終ジャッジ日時 2023-08-20 10:05:29
合計ジャッジ時間 975 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,876 KB
testcase_01 AC 19 ms
7,792 KB
testcase_02 AC 16 ms
7,880 KB
testcase_03 AC 18 ms
7,904 KB
testcase_04 AC 18 ms
7,796 KB
testcase_05 AC 20 ms
7,804 KB
testcase_06 AC 20 ms
7,944 KB
testcase_07 AC 17 ms
7,796 KB
testcase_08 AC 16 ms
7,860 KB
testcase_09 AC 23 ms
7,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int, input().split())

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

comb = (1 << n) - 1
dp = [0] * (comb + 1)
for c in range(1, comb):
    for i in range(n):
        f1 = 1 << i
        if not c & f1 == 0:
            continue
        cf = c | f1
        s = dp[c]
        for j in range(n):
            f2 = 1 << j
            if c & f2 == 0:
                continue
            s += score[j][i]
        dp[cf] = max(s, dp[cf])

print(dp[-1])
0