結果

問題 No.506 限られたジャパリまん
ユーザー char134217728
提出日時 2017-08-11 07:10:51
言語 Ruby
(3.4.1)
結果
AC  
実行時間 536 ms / 2,000 ms
コード長 743 bytes
コンパイル時間 130 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 14,592 KB
最終ジャッジ日時 2024-06-28 04:21:08
合計ジャッジ時間 5,439 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 25
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

h, w, k, p = gets.split.map &:to_i
m = {}
f = k.times.map do |i|
  x, y, n = gets.split
  m[33 * x.to_i + y.to_i] = i
  n
end
comb = [*0...k].combination(p).to_a
ans = [0, []]
comb.each do |arr|
  a = []
  (h+1).times do |_h|
    a << []
    (w+1).times do |_w|
      if _h == 0 && _w == 0
        a[_h][_w] = 1
        next
      end
      i = m[33 * _h + _w]
      if i && !arr.index(i)
        a[_h][_w] = 0
        next
      end
      if _h == 0
        a[_h][_w] = a[_h][_w-1]
        next
      end
      if _w == 0
        a[_h][_w] = a[_h-1][_w]
        next
      end
      a[_h][_w] = a[_h-1][_w] + a[_h][_w-1]
    end
  end
  if ans[0] < a[h][w]
    ans = [a[h][w], arr]
  end
end
puts ans[0] % (10**9+7)
ans[1].each{|i| puts f[i]}
0