結果

問題 No.357 品物の並び替え (Middle)
ユーザー ああいいああいい
提出日時 2022-03-24 22:19:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 92 ms / 5,000 ms
コード長 447 bytes
コンパイル時間 272 ms
コンパイル使用メモリ 82,324 KB
実行使用メモリ 68,812 KB
最終ジャッジ日時 2024-04-21 07:14:45
合計ジャッジ時間 2,404 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
61,184 KB
testcase_01 AC 45 ms
52,352 KB
testcase_02 AC 51 ms
59,008 KB
testcase_03 AC 53 ms
58,752 KB
testcase_04 AC 60 ms
62,592 KB
testcase_05 AC 57 ms
62,208 KB
testcase_06 AC 45 ms
52,096 KB
testcase_07 AC 45 ms
52,096 KB
testcase_08 AC 62 ms
63,360 KB
testcase_09 AC 73 ms
66,944 KB
testcase_10 AC 73 ms
67,328 KB
testcase_11 AC 66 ms
65,152 KB
testcase_12 AC 92 ms
68,812 KB
testcase_13 AC 70 ms
64,512 KB
testcase_14 AC 71 ms
66,560 KB
testcase_15 AC 66 ms
65,408 KB
testcase_16 AC 68 ms
65,684 KB
testcase_17 AC 64 ms
64,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

for bit in range(1,1 << N):
    for i in range(N):
        mask = 1 << i
        if bit & mask == 0:
            tmp = 0
            for v,s in G[i]:
                if bit >> v & 1:
                    tmp += s
            dp[bit | mask] = max(dp[bit | mask],dp[bit] + tmp)
print(dp[-1])
0