当前位置:网站首页>(Luogu) p1605 maze (once you enter the deep search, it's like a sea of bitterness, and from then on, it's a big die)
(Luogu) p1605 maze (once you enter the deep search, it's like a sea of bitterness, and from then on, it's a big die)
2022-07-21 03:18:00 【Leng Chi】
Background
Given a N*M The maze of squares , There is... In the maze T Obstacles , A barrier is not accessible . Given the coordinates of the starting point and the ending point , ask : Each square goes through at most 1 Time , How many schemes are there from the starting point coordinate to the ending point coordinate . There are four ways to move in the maze , Only one square can be moved at a time . The data ensures that there are no obstacles at the starting point .
Title Description
nothing
Input format
first line N、M and T,N For the line ,M Column ,T For the total number of obstacles . The second line starts at SX,SY, End coordinates FX,FY. Next T That's ok , Coordinates of each obstacle point .
Output format
Given the coordinates of the starting point and the ending point , Ask each square to go through at most 1 Time , The total number of schemes from the start coordinate to the end coordinate .
I/o sample
Input #1
2 2 1 1 1 2 2 1 2
Output #1
1
explain / Tips
【 Data scale 】
1≤N,M≤5
This is a classic. You can't search deeply in the classic , To tell the truth, just set a formula to search , Anyway, time will not exceed .
Friends who don't know deep search can go bibi On , See the Getting Started Guide .( Of course, you are also welcome to communicate with me )
( Recently, bloggers are busy playing games , Do the title , Study things , Has been ge, I'm sorry )
#include <iostream>
using namespace std;
int N,M,T;
int sx,sy,fx,fy;
int maze[6][6];
bool vis[6][6];
int sum=0;
int dir[4][2]={
{-1,0},{0,-1},{1,0},{0,1}};
bool in(int x,int y)
{
return x>=1&&x<=N&&y>=1&&y<=M;
}
void dfs(int x,int y)
{
if(x==fx&&y==fy)
{
sum++;
}
vis[x][y]=1;
for(int i=0;i<4;i++)
{
int tx=x+dir[i][0];
int ty=y+dir[i][1];
if(in(tx,ty)&&maze[tx][ty]!=1&&!vis[tx][ty])
{
dfs(tx,ty);
}
}
vis[x][y]=0;
}
int main()
{
cin>>N>>M>>T;
cin>>sx>>sy>>fx>>fy;
for(int i=0;i<T;i++)
{
int x,y;
cin>>x>>y;
maze[x][y]=1;
}
dfs(sx,sy);
cout<<sum<<endl;
return 0;
}
边栏推荐
猜你喜欢
阿里矢量图库 当前页全选
牛客BM6 判断链表中是否有环
【C】 Introduction to C language
<srcipt>标签上的 ‘defer‘和‘async‘ 属性的作用
试题 D: 修剪灌木
Chrome 进程架构
Transform streams into data products
Niuke bm6 judges whether there is a ring in the linked list
[dish of learning notes, dog learning C] get familiar with common keywords, define constants and macros
JMeter stress test is set to send a request every second
随机推荐
Tips for using Visual Studio shortcut keys
antd mobile 表单验证 rc-form 使用
[dish of learning notes, dog learning C] first learn operators and original code, inverse code, complement code
一致性哈希,虚拟节点,布隆过滤器
SIGIR‘22 推荐系统论文之对比学习篇
Visual Studio 快捷键的使用技巧
Apache Doris connects to SQL server through ODBC
【学习笔记之菜Dog学C】数组
P1020 [noip1999 popularization group] missile interception problem solution
【学习笔记之菜Dog学C】函数递归
Ctfshow web entry information collection WP (1-20) (detailed explanation)
[dish of learning notes dog learning C] detailed array name
[dish of learning notes dog learning C] chain access, function declaration and definition, goto statement
从输入URL到页面展示
页面性能:如何系统地优化页面?
nvm安装使用
文件编辑器vim的使用和介绍
Rpc:thrift framework
记一次笔记:Oracle条件语句
sklearn决策树(Decision Trees)模型