当前位置:网站首页>[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;
}边栏推荐
- Heavy forecast! Analysys, together with Microsoft and the Central University of Finance and economics, talks about the digital economy
- Opengauss kernel analysis: query rewriting
- Pursue and kill "wallet Assassin" all over the network
- MySQL series | log module
- Related knowledge of paging
- From casting sword to defending sword: the way to build the efficiency platform of didi project
- Dynamic kubernetes cluster capacity expansion of airbnb
- Breederdao's first proposal was released: the constitution of the Dao organization
- Turn: emotional internal friction is the biggest source of inefficiency in your life
- Educational codeforces round 89 (rated for Div. 2) ABC problem solution
猜你喜欢

How to implement the server anti blackmail virus system is a problem we have to consider

What does it operation and maintenance management mean? How to establish an effective IT operation and maintenance management system?

Specificity and five applications of Worthington alcohol dehydrogenase

Latest information of 2022 cloud computing skills competition

Pychart exits pytest mode (run pytest in mode)

Director of Shanghai Bureau of culture and Tourism: safety is the lifeline of culture and tourism, and we are seizing the new track of yuancosmos

Wireshark introduction and packet capturing principle and process

7.18 - daily question - 408

基于ABP实现DDD--领域逻辑和应用逻辑

Game partner topic: the cooperation between breederdao and monkeyleague kicked off
随机推荐
How to empty localstorage before closing a page
Director of Shanghai Bureau of culture and Tourism: safety is the lifeline of culture and tourism, and we are seizing the new track of yuancosmos
#648 (Div. 2)(A. Matrix Game、B. Trouble Sort、C. Rotation Matching)
Three modes of executing programs, memory and cache
第四章 驱动子系统开发
How to implement a state machine?
The position of the nth occurrence of MySQL in the string
The first meta universe auction of Chen Danqing's printmaking works will open tomorrow!
如何创建索引
Open source demo | release of open source example of arcall applet
Unity slider slider development
Yolov7:oserror: [winerror 1455] the page file is too small to complete the final solution of the operation
Harbor installation
DotNetCore. Cap notes
On let variable promotion
Chapter IV drive subsystem development
MySQL series | log module
Chapter III kernel development
Custom type
Game partner topic: the cooperation between breederdao and monkeyleague kicked off