题目:P1535[USACO08MAR]Cow Travelling S
#include<bits/stdc++.h>
using namespace std;
int dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
int t,cnt,r1,c1,r2,c2,n,m;
bool s[101][101];
void dfs(int t,int x,int y){
if(x==r2&&y==c2&&t==0){
cnt++;
}
if(!t||abs(x-r2)+abs(y-r2)>t)return;
for(int i=0;i<4;i++){
int xx=x+dx[i];
int yy=y+dy[i];
if(xx>=1&&yy>=1&&xx<=n&&yy<=m&&(s[xx][yy])){
dfs(t-1,xx,yy);
}
}
}
char temp;
int main(){
cin>>n>>m>>t;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>temp;
if(temp=='.') s[i][j]=true;
else s[i][j]=false;
}
}
cin>>r1>>c1>>r2>>c2;
dfs(t,r1,c1);
cout<<cnt;
return 0;
}