社区讨论

灌水区参与者 7已保存回复 10

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
9 条
当前快照
1 份
快照标识符
@m062l9ht
此快照首次捕获于
2024/08/23 10:05
2 年前
此快照最后确认于
2025/11/04 22:41
4 个月前
查看原帖
P1605 20pts
CPP
#include<bits/stdc++.h>
using namespace std;
int n,m,t,ans;
int vis[10][10],toup[10][10];
int sx,sy,fx,fy;
int x,y;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,-1,1};
void dfs(int x,int y,int fx,int fy){
	if(x==fx&&y==fy){
		ans++;
		return;
	}
	for(int i=1;i<=4;i++){
		int nx=x+dx[i],ny=y+dy[i];
		toup[nx][ny]=1;
		if(nx>n||nx<1||ny>m||ny<1&&toup[nx][ny]==0)continue;
		if(vis[nx][ny]==0){
			dfs(nx,ny,fx,fy);
		}
		toup[nx][ny]=0;
	}
}
int main(){
	cin>>n>>m>>t;
	cin>>sx>>sy>>fx>>fy;
	for(int i=1;i<=t;i++){
		cin>>x>>y;
		vis[x][y]=1;
	}
	dfs(sx,sy,fx,fy);
	cout<<ans;
	return 0;
}

回复

10 条回复,欢迎继续交流。

正在加载回复...