WIN = 101 LOSE = 102 C = 20 P = (0 .. 100).map{|v| v.quo(100).to_f } P1_3 = 1.quo(3).to_f P1_2 = 1.quo(2).to_f pp, q = gets.split.map(&:to_i) dp = Array.new(C + 1){ Array.new(101 + 2, 0.0) } dp[0][101] = P1_3 dp[0][102] = P1_3 dp[0][pp] = P1_3 C.times do |j| [WIN, LOSE].each {|r| dp[j + 1][r] = dp[j][r] } (0 .. 100).each do |i| # unuse [ [i + q, 100].min, WIN, LOSE].each {|r| dp[j + 1][r] += dp[j][i] * P[100 - i] * P1_3 } # use [ [i - q, 0].max, WIN, LOSE].each {|r| dp[j + 1][r] += dp[j][i] * P[i] * P1_2 } end end puts dp[C][101]