#include using namespace std; using ll = long long; using P = pair; const int dh[] = {1, -1, 0, 0}; const int dw[] = {0, 0, 1, -1}; double dp[2][10][10]; int cnt[10][10]; //bool used[10][10]; int main() { cin.tie(0); ios::sync_with_stdio(false); int r, c, t; cin >> r >> c >> t; int sy, sx, gy, gx; cin >> sy >> sx >> gy >> gx; vector s(r); for (int i = 0; i < r; i++) cin >> s[i]; /* used[sy][sx] = true; auto judge = [&](){ stack

stk; stk.emplace(sy, sx); while (!stk.empty()) { int h = stk.top().first, w = stk.top().second; stk.pop(); if (h == gy && w == gx) return true; used[h][w] = true; for (int j = 0; j < 4; j++) { int nh = h + dh[j], nw = w + dw[j]; if (nh < 0 || nh >= r || nw < 0 || nw >= c) continue; if (s[nh][nw] == '#') continue; if (used[nh][nw]) continue; stk.emplace(nh, nw); } } return false; }; if (!judge()) { cout << 0 << endl; return 0; }*/ for (int h = 0; h < r; h++) { for (int w = 0; w < c; w++) { for (int j = 0; j < 4; j++) { int nh = h + dh[j], nw = w + dw[j]; if (nh < 0 || nh >= r || nw < 0 || nw >= c) continue; cnt[h][w] += (s[nh][nw] == '.'); } } } dp[0][sy][sx] = 1; if (cnt[sy][sx] == 0) { cout << setprecision(10) << dp[0][gy][gx] << endl; return 0; } const int MAX_T = 10000; for (int i = 0; i < min(t, MAX_T); i++) { for (int h = 0; h < r; h++) { for (int w = 0; w < c; w++) { if (s[h][w] == '#') continue; for (int j = 0; j < 4; j++) { int nh = h + dh[j], nw = w + dw[j]; if (nh < 0 || nh >= r || nw < 0 || nw >= c) continue; if (s[nh][nw] == '#') continue; dp[(i + 1) % 2][nh][nw] += dp[i % 2][h][w] / cnt[h][w]; } if (i + 1 < min(t, MAX_T)) dp[i % 2][h][w] = 0; } } } if (t <= MAX_T) cout << setprecision(10) << dp[t % 2][gy][gx] << endl; else { if ((t - MAX_T) % 2 == 1) cout << setprecision(10) << dp[1 - MAX_T % 2][gy][gx] << endl; else cout << setprecision(10) << dp[MAX_T % 2][gy][gx] << endl; } return 0; }