結果

問題 No.357 品物の並び替え (Middle)
ユーザー Poina15Poina15
提出日時 2018-08-24 19:02:24
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 471 ms / 5,000 ms
コード長 534 bytes
コンパイル時間 459 ms
コンパイル使用メモリ 10,876 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2023-09-05 07:17:41
合計ジャッジ時間 2,866 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
7,824 KB
testcase_01 AC 16 ms
7,884 KB
testcase_02 AC 17 ms
7,840 KB
testcase_03 AC 17 ms
7,784 KB
testcase_04 AC 18 ms
7,788 KB
testcase_05 AC 18 ms
7,812 KB
testcase_06 AC 16 ms
7,840 KB
testcase_07 AC 15 ms
7,828 KB
testcase_08 AC 23 ms
7,936 KB
testcase_09 AC 212 ms
8,564 KB
testcase_10 AC 53 ms
7,824 KB
testcase_11 AC 54 ms
7,908 KB
testcase_12 AC 471 ms
8,704 KB
testcase_13 AC 214 ms
8,520 KB
testcase_14 AC 219 ms
8,448 KB
testcase_15 AC 54 ms
7,820 KB
testcase_16 AC 104 ms
8,264 KB
testcase_17 AC 54 ms
7,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M = map(int, input().split())
tbl = [[0] * N for _ in range(N)]
dp = [0] * (1 << N)
dp[0] = 0
for _ in range(M):
    a, b, score = map(int, input().split())
    tbl[a - 1][b - 1] = score

for msk in range(1 << N):
    for a in range(N):
        # a: 追加するitem
        s = dp[msk]
        if msk & (1 << a):
            continue
        for b in range(N):
            # b: 既に選んだitem
            if msk & (1 << b):
                s += tbl[a][b]
        dp[msk + (1 << a)] = max(dp[msk + (1 << a)], s)

print(dp[-1])
0