#include #define rep(i,a,b) for(int i=a;i=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() #pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b Vec; typedef vector Mat; Vec mulMatVec(Mat a, Vec b) { int n = b.size(); Vec ret(n, 0); rep(i, 0, n) rep(j, 0, n) ret[i] += a[i][j] * b[j]; return ret; } Mat mulMatMat(Mat a, Mat b) { int n = a.size(); Mat ret(n, Vec(n, 0)); rep(i, 0, n) rep(j, 0, n) rep(k, 0, n) ret[i][j] += a[i][k] * b[k][j]; return ret; } Mat fastpow(Mat x, ll n) { Mat ret(x.size(), Vec(x.size(), 0)); rep(i, 0, x.size()) ret[i][i] = 1; while (0 < n) { if ((n % 2) == 0) { x = mulMatMat(x, x); n >>= 1; } else { ret = mulMatMat(ret, x); --n; } } return ret; } /*---------------------------------------------------------------------------------------------------             ∧_∧       ∧_∧  (´<_` )  Welcome to My Coding Space!      ( ´_ゝ`) /  ⌒i     /   \    | |     /   / ̄ ̄ ̄ ̄/  |   __(__ニつ/  _/ .| .|____      \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ int H, W, T, SY, SX, GY, GX; string B[10]; int dx[4] = { 0, 1, 0, -1 }, dy[4] = { -1, 0, 1, 0 }; //--------------------------------------------------------------------------------------------------- void _main() { cin >> H >> W >> T >> SY >> SX >> GY >> GX; rep(y, 0, H) cin >> B[y]; Vec v(100); v[SY * 10 + SX] = 1; Mat m(100, Vec(100)); rep(y, 0, H) rep(x, 0, W) if(B[y][x] == '.'){ int cnt = 0; rep(i, 0, 4) { int xx = x + dx[i]; int yy = y + dy[i]; if (0 <= xx and xx < W and 0 <= yy and yy < H) { if (B[yy][xx] == '.') cnt++; } } double p = 1.0 / (double)cnt; rep(i, 0, 4) { int xx = x + dx[i]; int yy = y + dy[i]; if (0 <= xx and xx < W and 0 <= yy and yy < H) if (B[yy][xx] == '.') { m[yy * 10 + xx][y * 10 + x] = p; } } } v = mulMatVec(fastpow(m, T), v); //rep(y, 0, H) rep(x, 0, W) printf("[%d][%d] = %.10f\n", y, x, v[y * 10 + x]); double ans = v[GY * 10 + GX]; printf("%.10f\n", ans); }