結果

問題 No.90 品物の並び替え
ユーザー DialBirdDialBird
提出日時 2017-03-18 07:00:46
言語 Ruby
(3.3.0)
結果
AC  
実行時間 84 ms / 5,000 ms
コード長 399 bytes
コンパイル時間 333 ms
コンパイル使用メモリ 11,308 KB
実行使用メモリ 15,216 KB
最終ジャッジ日時 2023-09-17 21:25:16
合計ジャッジ時間 2,453 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
15,000 KB
testcase_01 AC 81 ms
15,136 KB
testcase_02 AC 79 ms
15,140 KB
testcase_03 AC 82 ms
15,056 KB
testcase_04 AC 80 ms
15,120 KB
testcase_05 AC 82 ms
15,112 KB
testcase_06 AC 82 ms
15,116 KB
testcase_07 AC 81 ms
15,016 KB
testcase_08 AC 78 ms
15,088 KB
testcase_09 AC 84 ms
15,216 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n, m = gets.chomp.split.map(&:to_i)
@scores = Array.new(n) { Array.new(n,0) }
@dp = {}

m.times do
  it_1, it_2, s = gets.chomp.split.map(&:to_i)
  @scores[it_1][it_2] = s
end

def solve(used, rest)
  return 0 if rest.empty?

  @dp[used.sort!] ||= rest.map do |i|
    sum = 0
    used.each { |j| sum += @scores[i][j] }
    sum += solve(used + [i], rest - [i])
  end.max
end

puts solve([], [*0...n])
0