P1535求调
  • 板块灌水区
  • 楼主zhz_2013
  • 当前回复5
  • 已保存回复5
  • 发布时间2024/10/3 15:03
  • 上次更新2024/10/3 17:14:25
查看原帖
P1535求调
980236
zhz_2013楼主2024/10/3 15:03

rt。
记录:https://www.luogu.com.cn/record/179681272
code:

#include<bits/stdc++.h>
using namespace std;
int n,m,t;
int mps[105][105];
int r1,c1,r2,c2;
const int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
int ans;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
inline void dfs(int x,int y,int step){
	if(step==t){
		if(x==r2&&y==c2)++ans;
		return;
	}
	if(abs(x-r2)+abs(y-c2)>t-step)return;
	if(x>n||y>m||x<=0||y<=0)return;
	if(!mps[x][y])return;
	for(int i=0;i<=3;i++){
		dfs(x+dx[i],y+dy[i],step+1);
	} 
}
int main(){
	n=read();
	m=read();
	t=read();
	string s;
	for(int i=1;i<=n;i++){
		cin>>s;
		for(int j=0;j<m;j++){
			if(s[j]=='*')mps[i][j+1]=0;
			else mps[i][j+1]=1;
		}
	}
	r1=read();
	c1=read();
	r2=read();
	c2=read();
	dfs(r1,c1,0);
	cout<<ans<<endl;
	return 0;
}

2024/10/3 15:03
加载中...