R, C, T = gets.split.map &:to_i Sy, Sx = gets.split.map &:to_i Gy, Gx = gets.split.map &:to_i Board = $<.map{|s|s.chomp.chars} # 偶奇が合わない man_dist = ((Sy+Sx) - (Gy+Gx)).abs if man_dist & 1 != T & 1 p 0 exit end DIRS = [[1,0],[-1,0],[0,1],[0,-1]] # スタート地点から動けない if DIRS.all?{|(dy, dx)| Board[Sy+dy][Sx+dx] == ?# } p Sy == Gy && Sx == Gx ? 1 : 0 exit end # 行き止まり used = R.times.map{ [p]*C } dfs = ->y, x{ return if used[y][x] || Board[y][x] == ?# used[y][x] = true DIRS.each{|(dy,dx)| dfs[y+dy, x+dx] } } dfs[Sy, Sx] if !used[Gy][Gx] p 0 exit end dirss = R.times.map{ [p]*C } (1...R).each{|y| (1...C).each{|x| next if Board[y][x] == ?# dirss[y][x] = DIRS.select{|(dy,dx)| Board[y+dy][x+dx] != ?# } } } probs = R.times.map{ [0r]*C } probs[Sy][Sx] = 1r [T, 1000+T%2].min.times{ next_probs = R.times.map{ [0r]*C } (1...R).each{|y| (1...C).each{|x| next if Board[y][x] == ?# prob = probs[y][x] dirs = dirss[y][x] dirs.each{|(dy, dx)| next_probs[y+dy][x+dx] += prob * 1r / dirs.size } } } probs = next_probs } p probs[Gy][Gx].to_f