結果

問題 No.90 品物の並び替え
ユーザー maimai
提出日時 2018-01-23 19:42:55
言語 Ruby
(3.3.0)
結果
AC  
実行時間 93 ms / 5,000 ms
コード長 409 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 11,176 KB
実行使用メモリ 15,540 KB
最終ジャッジ日時 2023-08-26 23:52:30
合計ジャッジ時間 2,591 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,068 KB
testcase_01 AC 88 ms
15,088 KB
testcase_02 AC 81 ms
14,996 KB
testcase_03 AC 84 ms
15,148 KB
testcase_04 AC 83 ms
15,120 KB
testcase_05 AC 87 ms
15,212 KB
testcase_06 AC 87 ms
15,064 KB
testcase_07 AC 83 ms
15,084 KB
testcase_08 AC 80 ms
15,004 KB
testcase_09 AC 93 ms
15,540 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def ascan; gets.split.map(&:to_i);end


N,M = ascan
score = Hash.new(0)
M.times do
    i,j,x = ascan
    score[[i,j]] = x
end

NP = 1<< N

dp = Array.new(NP, 0)

0.upto(NP-2) do |b|
    N.times do |i|
        next if b & (1<< i) != 0
        
        t = (0...N).map{|j| b & (1<< j) == 0 ? 0 : score[[j,i]]}.reduce(:+)
        
        dp[b | (1<< i)] = [dp[b | (1<< i)], dp[b]+t].max
    end
end

p dp[NP-1]
0