結果

問題 No.357 品物の並び替え (Middle)
ユーザー ryomacryomac
提出日時 2024-01-12 01:27:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 68 ms / 5,000 ms
コード長 439 bytes
コンパイル時間 3,190 ms
コンパイル使用メモリ 81,444 KB
実行使用メモリ 70,464 KB
最終ジャッジ日時 2024-01-12 01:27:17
合計ジャッジ時間 2,529 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
62,232 KB
testcase_01 AC 34 ms
53,460 KB
testcase_02 AC 42 ms
59,888 KB
testcase_03 AC 41 ms
59,856 KB
testcase_04 AC 43 ms
62,232 KB
testcase_05 AC 44 ms
62,232 KB
testcase_06 AC 38 ms
59,472 KB
testcase_07 AC 34 ms
53,460 KB
testcase_08 AC 50 ms
64,196 KB
testcase_09 AC 66 ms
68,432 KB
testcase_10 AC 54 ms
66,248 KB
testcase_11 AC 53 ms
66,248 KB
testcase_12 AC 68 ms
70,464 KB
testcase_13 AC 64 ms
68,424 KB
testcase_14 AC 62 ms
68,424 KB
testcase_15 AC 58 ms
68,468 KB
testcase_16 AC 57 ms
66,376 KB
testcase_17 AC 51 ms
66,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M = map(int, input().split())
score = [[0] * N for _ in range(N)]
for _ in range(M):
    x, y, z = map(int, input().split())
    score[x][y] = z

dp = [0] * (1 << N)
for S in range(1 << N):
    for i in range(N):
        if S >> i & 1:
            continue
        cost = 0
        for j in range(N):
            if S >> j & 1:
                cost += score[i][j]
        dp[S | 1 << i] = max(dp[S | 1 << i], dp[S] + cost)
print(dp[-1])
0