class Calc0058 EPS = 1e-3 def initialize(args) args = args.map { |l| l.chomp.split(/\s+/) } @n = args.shift.first.to_i @k = args.shift.first.to_i end def run sais_taro = Array.new(@n - @k) { (1..6).to_a } + Array.new(@k) { [4, 5, 6] * 2 } sais_jiro = Array.new(@n) { (1..6).to_a } hist_taro = make_hist(sais_taro, [1]) hist_jiro = make_hist(sais_jiro, [1]) hist_jiro.map.with_index { |h, i| h * (hist_taro.drop(i + 1).inject(:+) || 0) }.inject(:+).to_f / 6 ** (@n * 2) end def make_hist(sais, hist) sais.each do |sai| hist = sai.map { |d| [0] * d + hist + [0] * (sai.max - d) }.transpose.map { |r| r.inject(:+) } end hist end end puts Calc0058.new(STDIN.readlines).run if __FILE__ == $0