結果

問題 No.357 品物の並び替え (Middle)
ユーザー ckawatakckawatak
提出日時 2017-10-11 20:49:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 69 ms / 5,000 ms
コード長 783 bytes
コンパイル時間 186 ms
コンパイル使用メモリ 81,984 KB
実行使用メモリ 69,888 KB
最終ジャッジ日時 2024-04-28 16:12:49
合計ジャッジ時間 2,214 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
62,208 KB
testcase_01 AC 35 ms
51,456 KB
testcase_02 AC 42 ms
60,160 KB
testcase_03 AC 54 ms
60,544 KB
testcase_04 AC 46 ms
62,080 KB
testcase_05 AC 46 ms
61,952 KB
testcase_06 AC 38 ms
57,984 KB
testcase_07 AC 35 ms
51,968 KB
testcase_08 AC 51 ms
64,768 KB
testcase_09 AC 66 ms
68,480 KB
testcase_10 AC 54 ms
65,536 KB
testcase_11 AC 52 ms
65,024 KB
testcase_12 AC 69 ms
69,632 KB
testcase_13 AC 66 ms
68,096 KB
testcase_14 AC 66 ms
69,888 KB
testcase_15 AC 55 ms
66,432 KB
testcase_16 AC 58 ms
66,944 KB
testcase_17 AC 53 ms
65,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M = list(map(int, input().split(' ')))

S = []
for i in range(N):
    S.append([0 for _ in range(N)])

for i in range(M):
    f, t, s = list(map(int, input().split(' ')))
    S[f][t] = s

# score for each bit vector expressing that each number is used or not    
dp = [0 for _ in range(1 << N)]

for p in range(1 << N):
    for i in range(N):
        # if 'i' is not used yet at p, calculate the score when 'i' is used at p
        if (p & (1 << i)) == 0:
            score = dp[p]
            for j in range(N):
                if (p & (1 << j)) != 0:
                    score += S[j][i]
            # update the score when 'i' used at p
            dp[p | (1 << i)] = max(dp[p | (1 << i)], score)
# check the score when all the number is used            
print(dp[(1 << N)-1])
0