結果
| 問題 | No.357 品物の並び替え (Middle) |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-11-15 13:37:24 |
| 言語 | PyPy2 (7.3.20) |
| 結果 |
AC
|
| 実行時間 | 92 ms / 5,000 ms |
| + 470µs | |
| コード長 | 527 bytes |
| 記録 | |
| コンパイル時間 | 58 ms |
| コンパイル使用メモリ | 81,148 KB |
| 実行使用メモリ | 84,272 KB |
| 最終ジャッジ日時 | 2026-07-18 11:00:28 |
| 合計ジャッジ時間 | 2,701 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 |
ソースコード
def maxProfit(board,dp,_st):
st=_st
maxP=0
i=0
while True:
bonus=0
if st & 2**i != 0 and i in board:
for k,s in board[i].items():
if st & 2**k != 0:
bonus += s
maxP = max(maxP, dp[st-2**i]+bonus)
i+=1
if st<2**i: break
return maxP
N,M=map(int,raw_input().split())
board={}
for _ in xrange(M):
i1,i2,s=map(int,raw_input().split())
if i2 not in board: board[i2]={}
board[i2][i1]=s
dp=[0]*(2**N)
for i in xrange(1,2**N):
dp[i]=maxProfit(board,dp,i)
print dp[2**N-1]