結果

問題 No.357 品物の並び替え (Middle)
ユーザー vwxyzvwxyz
提出日時 2022-04-30 04:29:37
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 253 ms / 5,000 ms
コード長 370 bytes
コンパイル時間 787 ms
コンパイル使用メモリ 10,932 KB
実行使用メモリ 8,636 KB
最終ジャッジ日時 2023-09-11 20:55:47
合計ジャッジ時間 2,296 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
7,812 KB
testcase_01 AC 15 ms
7,808 KB
testcase_02 AC 16 ms
7,812 KB
testcase_03 AC 16 ms
7,780 KB
testcase_04 AC 17 ms
7,752 KB
testcase_05 AC 17 ms
7,752 KB
testcase_06 AC 15 ms
7,948 KB
testcase_07 AC 16 ms
7,816 KB
testcase_08 AC 19 ms
7,864 KB
testcase_09 AC 103 ms
8,340 KB
testcase_10 AC 38 ms
7,756 KB
testcase_11 AC 33 ms
7,736 KB
testcase_12 AC 253 ms
8,636 KB
testcase_13 AC 128 ms
8,364 KB
testcase_14 AC 113 ms
8,200 KB
testcase_15 AC 31 ms
7,812 KB
testcase_16 AC 64 ms
8,344 KB
testcase_17 AC 39 ms
7,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline=sys.stdin.readline

N,M=map(int,readline().split())
item=[[] for i in range(N)]
for _ in range(M):
    x,y,s=map(int,readline().split())
    item[y].append((x,s))
dp=[0]*(1<<N)
for bit in range(1<<N):
    for y in range(N):
        if bit&1<<y:
            dp[bit]=max(dp[bit],dp[bit^1<<y]+sum(s for x,s in item[y] if bit&1<<x))
ans=dp[-1]
print(ans)
0