博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
P1605 迷宫
阅读量:7216 次
发布时间:2019-06-29

本文共 747 字,大约阅读时间需要 2 分钟。

dfs

#include
#include
#include
#include
#include
#include
#include
using namespace std;int ans=0,n,m,t,sx,sy,tx,ty;bool f[10][10];int dx[]={ 0,1,-1,0,0},dy[]={ 0,0,0,-1,1};void dfs(int x,int y){ if(x==tx&&y==ty) { ans++; return; } for(int i=1;i<=4;i++) { int kx=x+dx[i],ky=y+dy[i]; if(kx<=m&&kx>=1&&ky<=n&&ky>=1) if(!f[kx][ky]) { f[kx][ky]=true; dfs(kx,ky); f[kx][ky]=false; } }}int main(){ scanf("%d%d%d",&n,&m,&t); scanf("%d%d%d%d",&sx,&sy,&tx,&ty); for(int i=1;i<=t;i++) { int x,y; scanf("%d%d",&x,&y); f[x][y]=true; } f[sx][sy]=true; dfs(sx,sy); printf("%d",ans); return 0;}

转载于:https://www.cnblogs.com/dfsac/p/6819743.html

你可能感兴趣的文章
使用firefox和selenium模拟点击js获取更多评论
查看>>
SQL-mysql设置utf8编码方法
查看>>
5.4 异步TCP编程(三)
查看>>
采访Hadley Wickham
查看>>
iframe中的各种跳转方法
查看>>
oracle编程、操作不良习惯总结
查看>>
每天一个linux命令(26):用SecureCRT来上传和下载
查看>>
Oracle 表空间状态
查看>>
为redis分配一个新的端口
查看>>
利用Python做绝地科学家(外挂篇)
查看>>
费下载最新版万能视频格式转换器是一款功能强大的全能视频格式转换软件
查看>>
算法实战——多叉树全路径遍历
查看>>
MySQL数据类型和常用字段属性总结
查看>>
斑点检测(LoG,DoG)(下)
查看>>
《CLR Via C# 第3版》笔记之(二十二) - APM和EAP
查看>>
洛谷P5111 zhtobu3232的线段树
查看>>
Angular Cli 创建的Angular项目应用本地css文件和js文件
查看>>
java代码getHostAddress .getHostName()的练习
查看>>
【转】一个孩子关于MaD的思考概述
查看>>
C 再识数组指针 指针数组的概念
查看>>