70分求助
查看原帖
70分求助
914413
xiaozhichen123楼主2024/1/17 10:28
#include<bits/stdc++.h>
using namespace std;
int x[4]={-1,1,0,0};
int y[4]={0,0,-1,1};
int n,m,t,sx,sy,fx,fy,tx,ty,ans;
int s[1001][1001];
bool u[1001][1001];
void dfs(int a,int b){
	if(a==fx&&b==fy){
		ans++;
	}else{
		for(int i=0;i<4;i++){
			if(a+x[i]>0&&a+x[i]<=m){
				if(b+y[i]>0&&b+y[i]<=n){
					if(!u[a+x[i]][b+y[i]]){
						u[a+x[i]][b+y[i]]=1;
						dfs(a+x[i],b+y[i]);
						u[a+x[i]][b+y[i]]=0;
					}
				}
			}
		}
	}
}
int main(){
	cin>>n>>m>>t;
	cin>>sx>>sy>>fx>>fy;
	for(int i=1;i<=t;i++){
		cin>>tx>>ty;
		u[tx][ty]=1;
	}
	dfs(sx,sy);
	cout<<ans;
}
2024/1/17 10:28
加载中...