#P1535. [USACO08MAR] Cow Travelling S

[USACO08MAR] Cow Travelling S

Description

Cows wander on a pasture divided into NN rows and MM columns (2N,M1002 \leq N, M \leq 100), trying to find the tastiest grass.

At some moment, Farmer John sees Bessie at position (R1,C1)(R_1, C_1). Exactly TT (0<T150 < T \leq 15) seconds later, FJ runs into Bessie at position (R2,C2)(R_2, C_2). FJ does not know whether Bessie visited (R2,C2)(R_2, C_2) at any time during those TT seconds; he only knows that she is there now.

Let SS be the number of paths the cow can take to go from (R1,C1)(R_1, C_1) to (R2,C2)(R_2, C_2) in TT seconds. FJ wants a program to compute this value. Each second, the cow moves horizontally or vertically by a distance of 11 (the cow is always moving and will not stay at the same point in any second). Some places on the pasture have trees. Of course, the cow cannot step on a tree, and she will not leave the pasture.

You are given a map of the whole pasture, where . means open grass and * means a blocking tree. Your task is to compute how many different paths a cow can take to move from (R1,C1)(R_1, C_1) to (R2,C2)(R_2, C_2) in TT seconds.

Input Format

The first line contains 33 space-separated integers: N,M,TN, M, T.

Then NN lines follow: the ii-th line has MM consecutive characters describing row ii of the pasture. Each character is guaranteed to be either . or *.

The last line contains 44 integers R1,C1,R2,C2R_1, C_1, R_2, C_2.

Output Format

Output the number of ways to move from (R1,C1)(R_1, C_1) to (R2,C2)(R_2, C_2).

4 5 6
...*.
...*.
.....
.....
1 3 1 5
1

Hint

There is only one way for the cow to go from (1,3)(1, 3) to (1,5)(1, 5) in 66 seconds, by going around the tree in front of her.

Translated by ChatGPT 5