当前位置:网站首页>[summer daily question] Luogu p1605 maze
[summer daily question] Luogu p1605 maze
2022-07-25 01:22:00 【AC_ Dragon】
Topic link :P1605 maze - Luogu | New ecology of computer science education (luogu.com.cn)
Title Description
Given a N×M The maze of squares , There is... In the maze T Obstacles , A barrier is not accessible .
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 .
Given the coordinates of the starting point and the ending point , Each square can pass at most once , How many schemes are there from the starting point coordinate to the end point coordinate .
Input format
The first line is three positive integers N,M,T, Respectively represent the length and width of the maze and the total number of obstacles .
The second line is four positive integers SX,SY,FX,FY, among ,SX,SY Represents the starting point coordinates ,FX,FY Represents the coordinates of the end point .
Next T That's ok , Two positive integers per line , Represents the coordinates of the obstacle point .
Output format
Output the total number of schemes from the start coordinate to the end coordinate .
Examples #1
The sample input #1
2 2 1
1 1 2 2
1 2Sample output #1
1Tips
about 100% The data of ,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}, // Right
{1,0}, // Next
{0,-1},// Left
{-1,0}};// On
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;
}边栏推荐
- How to empty localstorage before closing a page
- Interview questions
- [FAQ of waiting insurance] can the waiting insurance evaluation organization help with the waiting insurance rectification?
- 2012.4.13 360 written examination summary
- Wireshark packet capturing and rapid packet location skills
- Sort out some scattered knowledge points by yourself
- Solution to the shortest Hamilton path problem
- MySQL series | log module
- The difference between sigsuspend and sigwait
- Detailed explanation of zero length array in C language (1) [information at the end of the article]
猜你喜欢

7.19 - daily question - 408

Wireshark introduction and packet capturing principle and process

Pads copper laying

On let variable promotion

Pychart exits pytest mode (run pytest in mode)

Heavy forecast! Analysys, together with Microsoft and the Central University of Finance and economics, talks about the digital economy

Windows security hardening -- close unnecessary ports
![Nacos hand to hand teaching [i] dynamic configuration of Nacos](/img/c4/ae29475c795e879683227de5ba3cfc.png)
Nacos hand to hand teaching [i] dynamic configuration of Nacos

Specificity and five applications of Worthington alcohol dehydrogenase

Turn: emotional internal friction is the biggest source of inefficiency in your life
随机推荐
Heavy forecast! Analysys, together with Microsoft and the Central University of Finance and economics, talks about the digital economy
Google Earth engine - 1980 present global pressure, temperature, wind and other data sets
Turn: emotional internal friction is the biggest source of inefficiency in your life
How to better use the touchpad of notebook
Volley7 – networkdispatcher obtains data from the network [easy to understand]
Take the first place in the International Olympic Games in mathematics, physics and chemistry, and win all the gold medals. Netizen: the Chinese team is too good
Shell judges whether the file exists and whether the file size is 0
Wireshark introduction and packet capturing principle and process
第四章 驱动子系统开发
UXDB在不知道明文密码的情况下重置密码
7.20 - daily question - 408
The current situation of the industry is disappointing. After working, I returned to UC Berkeley to study for a doctoral degree
Password input box and coupon and custom soft keyboard
Fabric. JS centered element
Solution to the shortest Hamilton path problem
C language word translation (to help understand the basic meaning of words) is updated from time to time
Top priority of dry goods: common indicators and terms in data analysis!
Tiktok iqiyi announced cooperation, long and short video handshake and reconciliation?
Latest information of 2022 cloud computing skills competition
Redis transaction learning