結果

問題 No.357 品物の並び替え (Middle)
ユーザー fumofumofunifumofumofuni
提出日時 2021-09-13 20:48:03
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 106 ms / 5,000 ms
コード長 416 bytes
コンパイル時間 820 ms
コンパイル使用メモリ 86,812 KB
実行使用メモリ 76,452 KB
最終ジャッジ日時 2023-09-08 04:31:19
合計ジャッジ時間 3,129 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
76,312 KB
testcase_01 AC 72 ms
71,136 KB
testcase_02 AC 80 ms
76,300 KB
testcase_03 AC 82 ms
76,208 KB
testcase_04 AC 83 ms
76,244 KB
testcase_05 AC 84 ms
76,180 KB
testcase_06 AC 78 ms
75,584 KB
testcase_07 AC 75 ms
71,148 KB
testcase_08 AC 89 ms
76,452 KB
testcase_09 AC 104 ms
76,364 KB
testcase_10 AC 89 ms
76,280 KB
testcase_11 AC 91 ms
76,220 KB
testcase_12 AC 106 ms
76,340 KB
testcase_13 AC 104 ms
76,320 KB
testcase_14 AC 106 ms
76,276 KB
testcase_15 AC 93 ms
76,264 KB
testcase_16 AC 94 ms
76,364 KB
testcase_17 AC 89 ms
76,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M=map(int,input().split())
mat=[[0]*15 for i in range(15)]
for i in range(M):
    u,v,s=map(int,input().split())
    mat[u][v]=s

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