显示代码纯文本
#include <iostream>
#include <cstdio>
#include <memory.h>
using namespace std;
const short RUL[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
int f[110][110],tim[110][110];
char map[110][110];
bool used[110][110];
int main(void)
{
freopen("ctravel.in","r",stdin);
freopen("ctravel.out","w",stdout);
int i,j,k,n,m,t,x,y,xe,ye,tnow;
cin>>n>>m>>t;
for (i=1;i<=n;i++)
for (j=1;j<=m;j++)
cin>>map[i][j];
cin>>x>>y>>xe>>ye;
tim[x][y]=1;
f[x][y]=1;
tnow=1;
while (tnow<=t)
{
memset(used,0,sizeof(used));
for (i=1;i<=n;i++)
for (j=1;j<=m;j++)
{
if (tim[i][j]==tnow)
{
for (k=0;k<4;k++)
{
x=RUL[k][0]+i;
y=RUL[k][1]+j;
if (map[x][y]!='.')
continue;
tim[x][y]=tnow+1;
if (!used[x][y])
{
f[x][y]=f[i][j];
used[x][y]=1;
}
else
{
f[x][y]+=f[i][j]+(tnow==1);
}
}
}
}
tnow++;
}
if (tim[xe][ye]==t+1)
cout<<f[xe][ye]<<endl;
else
cout<<"0\n";
return(0);
}