1 #include<cstdio>
2 #include<iostream>
3 #include<queue>
4 using namespace std;
5
6 struct node{
7 int x,y,step;
8 };
9
10 const int dir[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};
11 int r,c,t,sx,sy,tx,ty;
12 int map[1000][1000];
13 int tracing[1000][1000];
14 int cnt[1000][1000];
15 bool book[1000][1000];
16 char ctr;
17
18 void bfs(){
19 queue<node> Q;
20 Q.push((node){tx,ty,0});
21 tracing[tx][ty] = -1;
22
23 while(!Q.empty()){
24 node now = Q.front();
25 Q.pop();
26
27 for(int i = 0;i < 4;i++){
28 int nowx = now.x+dir[i][0];
29 int nowy = now.y+dir[i][1];
30 if((!tracing[nowx][nowy] || tracing[nowx][nowy] >= now.step+1) && map[nowx][nowy]){
31 tracing[nowx][nowy] = now.step+1;
32 if(!book[nowx][nowy]){
33 Q.push((node){nowx,nowy,now.step+1});
34 book[nowx][nowy] = true;
35 }
36 }
37 }
38 book[now.x][now.y] = false;
39 }
40 }
41
42 void dfs(int nowx,int nowy,int step){
43 if(step == t) cnt[nowx][nowy]++;
44 else{
45 for(int i = 0;i < 4;i++){
46 int x = nowx+dir[i][0];
47 int y = nowy+dir[i][1];
48
49 if(map[x][y] && step+tracing[x][y] <= t) dfs(x,y,step+1);
50 }
51 }
52 }
53
54 int main(){
55 scanf("%d%d%d",&r,&c,&t);
56 for(int i = 1;i <= r;i++){
57 for(int j = 1;j <= c;j++){
58 cin >> ctr;
59 if(ctr == ‘.‘) map[i][j] = 1;
60 }
61 }
62
63 scanf("%d%d%d%d",&sx,&sy,&tx,&ty);
64
65 bfs();
66
67 dfs(sx,sy,0);
68
69 printf("%d",cnt[tx][ty]);
70
71 // for(int i = 1;i <= r;i++){
72 // /cout << endl;
73 // for(int j = 1;j <= c;j++){
74 // printf("%d ",tracing[i][j]);
75 // }
76 // }
77
78 return 0;
79 }