当前位置:网站首页>【暑期每日一题】洛谷 P1605 迷宫
【暑期每日一题】洛谷 P1605 迷宫
2022-07-20 11:46:00 【AC_Dragon】
题目链接:P1605 迷宫 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
题目描述
给定一个 N×M 方格的迷宫,迷宫里有 T 处障碍,障碍处不可通过。
在迷宫中移动有上下左右四种方式,每次只能移动一个方格。数据保证起点上没有障碍。
给定起点坐标和终点坐标,每个方格最多经过一次,问有多少种从起点坐标到终点坐标的方案。
输入格式
第一行为三个正整数 N,M,T,分别表示迷宫的长宽和障碍总数。
第二行为四个正整数 SX,SY,FX,FY,其中,SX,SY 代表起点坐标,FX,FY 代表终点坐标。
接下来 T 行,每行两个正整数,表示障碍点的坐标。
输出格式
输出从起点坐标到终点坐标的方案总数。
样例 #1
样例输入 #1
2 2 1
1 1 2 2
1 2
样例输出 #1
1
提示
对于 100% 的数据,1 <= N,M <= 5,1 <= T <= 10,1 <= SX,FX <= n,1 <= SY,FY <= m。
AC code:(DFS)
#include<iostream>
#include<algorithm>
using namespace std;
/*
0 0 0 0 0 0
0 1 1 1 1 0
0 1 2 2 1 0
0 1 2 * 1 0
0 1 1 1 1 0
0 0 0 0 0 0
*/
int dir[4][2]={
{0,1}, // 右
{1,0}, // 下
{0,-1},// 左
{-1,0}};// 上
int a[10][10],book[10][10];
int startx,starty,endx,endy;
int cnt;
void dfs(int x,int y,int step)
{
if(x==endx && y==endy)
{
cnt++;
return ;
}
for(int i=0;i<4;i++)
{
int tx=x+dir[i][0];
int ty=y+dir[i][1];
if(a[tx][ty]==1 && book[tx][ty]==0)
{
book[tx][ty]=1;
dfs(tx,ty,step+1);
book[tx][ty]=0;
}
}
return ;
}
int main()
{
int n,m,t;
cin>>n>>m>>t;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
a[i][j]=1;
cin>>startx>>starty>>endx>>endy;
while(t--)
{
int i,j;
cin>>i>>j;
a[i][j]=2;
}
book[startx][starty]=1;
dfs(startx,starty,0);
cout<<cnt<<endl;
return 0;
}
边栏推荐
- 【单片机仿真项目】8×8 LED点阵图形显示
- How to download video files
- 外设篇:ADC
- 利用wget下载文件和网页
- C traps and defects Chapter 2 syntax "traps" 2.1 understanding function declarations
- Google Earth Engine——MERRA-2 M2T1NXAER:1980-2022年气溶胶逐日数据集
- Kusionstack open source | exploration and practice of kusion model library and tool chain
- The ability to detect movement in vivo and build a safe and reliable payment level "face brushing" experience
- 力扣sql刷题系列(三)
- PG operation and maintenance -- common management commands
猜你喜欢
CV (2)- image classification
动作活体检测能力,构建安全可靠的支付级“刷脸”体验
Rust之fluid用法(fltk ui 设计器)
300 题: 第五讲 特征值与特征向量
Interface automation test -- pytest test test case design
Open source remote desktop software rustdesk
PG运维篇--常用管理命令
动手搭建一个三个节点的eureka集群
CV (3)- Loss Functions and Optimization
[Ping detection] use the ping command to check the network connection
随机推荐
C和指针 第1章 词法“陷阱” 1.4 整型常量
Rust之fluid用法(fltk ui 设计器)
QT之隐藏控件
年度重磅!华为云2021应用构建技术实践精选集,七大领域400页+云上开发宝典 | 云享·书库 No.02 期推荐(附免费下载)
Open source remote desktop software rustdesk
高能同步辐射光源科学数据管理策略研究与应用
[Ping detection] use the ping command to check the network connection
Kusionstack open source | exploration and practice of kusion model library and tool chain
C陷阱与缺陷 第1章 词法“陷阱” 1.5 字符与字符串
Moco V2: further upgrade of Moco series
C and pointer Chapter 2 syntax "trap" 2.2 priority of operators
1260. 二维网格迁移 : 简单构造模拟题
外设篇:LCD显示器
华为云GaussDB(for Redis)揭秘第23期:用GaussDB(for Redis)存画像,推荐业务轻松降本60%
Deit: attention can also be distilled
Start to build a three node Eureka cluster
Do you really understand form data and request payload?
【单片机仿真项目】8×8 LED点阵图形显示
ping 命令还能这么玩?
Deeply understand MySQL transaction isolation level and locking mechanism