結果
| 問題 |
No.357 品物の並び替え (Middle)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-11-15 13:37:24 |
| 言語 | Python2 (2.7.18) |
| 結果 |
AC
|
| 実行時間 | 248 ms / 5,000 ms |
| コード長 | 527 bytes |
| コンパイル時間 | 897 ms |
| コンパイル使用メモリ | 6,912 KB |
| 実行使用メモリ | 6,816 KB |
| 最終ジャッジ日時 | 2024-11-26 01:41:15 |
| 合計ジャッジ時間 | 1,839 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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]