結果
問題 |
No.90 品物の並び替え
|
ユーザー |
|
提出日時 | 2017-03-18 07:00:46 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 89 ms / 5,000 ms |
コード長 | 399 bytes |
コンパイル時間 | 146 ms |
コンパイル使用メモリ | 7,552 KB |
実行使用メモリ | 12,416 KB |
最終ジャッジ日時 | 2024-07-04 15:20:24 |
合計ジャッジ時間 | 1,654 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 9 |
コンパイルメッセージ
Syntax OK
ソースコード
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])