#include using namespace std; #define INF_LL (ll)1e18 #define INF (int)1e9 #define REP(i, n) for(int i = 0;i < (n);i++) #define FOR(i, a, b) for(int i = (a);i < (b);i++) #define all(x) x.begin(),x.end() #define fs first #define sc second using int32 = int_fast32_t; using uint32 = uint_fast32_t; using int64 = int_fast64_t; using uint64 = uint_fast64_t; using PII = pair; using PLL = pair; const double eps = 1e-10; templateinline void chmin(A &a, B b){if(a > b) a = b;} templateinline void chmax(A &a, B b){if(a < b) a = b;} double table[10][10][10][10][32] = {}; int32 dx[4] = {-1, 0, 0, 1}; int32 dy[4] = {0, -1, 1, 0}; int64 sx, sy, gx, gy; int64 R, C, T; map, double> mp; double dfs(int32 py, int32 px, int64 rest){ if(mp[{py, px, rest}]) return mp[{py, px, rest}] == -1 ? 0 : mp[{py, px,rest}]; int32 cnt = 0, bit = 1; while(bit <= rest){ bit*=2; cnt++; } bit /= 2; cnt--; if(rest == bit){ if(table[py][px][gy][gx][cnt] == 0){ mp[{py, px, rest}] = -1; return 0; }else{ return mp[{py, px, rest}] = table[py][px][gy][gx][cnt]; } } double res = 0; REP(i, R){ REP(j, C){ res += table[py][px][i][j][cnt]*dfs(i, j, rest-bit); } } if(res == 0){ mp[{py, px, rest}] = -1; return 0; }else{ return mp[{py, px, rest}] = res; } } int main(void){ cin >> R >> C >> T; cin >> sy >> sx >> gy >> gx; string f[10]; REP(i, R) cin >> f[i]; FOR(i, 1, R-1){ FOR(j, 1, C-1){ if(f[i][j] == '#') continue; int32 cnt = 0; REP(k, 4){ int32 yy = i+dy[k], xx = j+dx[k]; if(f[yy][xx] == '.') cnt++; } REP(k, 4){ int32 yy = i+dy[k], xx = j+dx[k]; if(f[yy][xx] == '.'){ table[i][j][yy][xx][0] = 1.0/(double)cnt; } } if(cnt == 0) table[i][j][i][j][0] = 1; } } REP(t, 31){ REP(i, R){ REP(j, C){ REP(k, R){ REP(l, C){ REP(m, R){ REP(n, C){ table[i][j][k][l][t+1] += table[i][j][m][n][t]*table[m][n][k][l][t]; } } } } } } } cout << fixed << setprecision(10) << dfs(sy, sx, T) << endl; }