//#define _GLIBCXX_DEBUG #include #define rep(i, n) for(int i=0; i; using vs = vector; using vi = vector; using vvi = vector; template using PQ = priority_queue; template using PQG = priority_queue, greater >; const int INF = 100010001; const ll LINF = (ll)INF*INF*10; template inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);} template inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);} template istream &operator>>(istream &is, pair &p) { return is >> p.first >> p.second;} template ostream &operator<<(ostream &os, const pair &p) { return os << p.first << ' ' << p.second;} const int N = 10; //head int r, c, t; P S, G; string s[N]; int di[] = {1, 0, -1, 0}; int dj[] = {0, 1, 0, -1}; using V = vector; using M = vector; inline int num(int i, int j) {return i*c+j;} inline int num(P x) {return num(x.first, x.second);} M mul(const M &a, const M b) { int n = a.size(); M res(n, V(n)); rep(i, n) rep(j, n) rep(k, n) res[i][j] += a[i][k] * b[k][j]; return res; } M pow(const M &a, ll p) { int n = a.size(); if(!p) { M res(n, V(n)); rep(i, n) res[i][i] = 1.0; return res; } M res = pow(a, p>>1); res = mul(res, res); if(p&1) res = mul(res, a); return res; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> r >> c >> t; cin >> S >> G; rep(i, r) cin >> s[i]; const int x = r*c; M mat(x, V(x)); for(int i = 1; i < r-1; i++) for(int j = 1; j < c-1; j++) { if(s[i][j] == '#') continue; int cnt = 0; rep(k, 4) { int ni = i+di[k]; int nj = j+dj[k]; if(s[ni][nj] == '#') continue; cnt++; } rep(k, 4) { int ni = i+di[k]; int nj = j+dj[k]; if(s[ni][nj] == '#') continue; mat[num(ni, nj)][num(i, j)] = (ld)1/cnt; } if(!cnt) { mat[num(i, j)][num(i, j)] = 1.0; } } mat = pow(mat, t); cout << fixed << setprecision(20) << mat[num(G)][num(S)] << endl; }