P1605 maze, p1605 maze

Source: Internet
Author: User

P1605 maze, p1605 maze
Background

Maze [Problem description]

Given a maze of N * M squares, there are T obstacles in the Maze and obstacles cannot pass through. Given the start coordinate and

Endpoint coordinate: How many methods can each square go through at most one time from the start point coordinate to the end point coordinate. In the maze

China Mobile has four ways to move up, down, and left. Only one square can be moved at a time. There are no barriers to data assurance.

Input sample output sample

[Data scale]

1 ≤ N, M ≤ 5

Question description input/output format Input Format:

[Input]

The first row N, M, and T, N is the row, M is the column, and T is the total number of obstacles. Second line starting point coordinate SX, SY, end point

Coordinate FX, FY. The coordinates of each behavior obstacle point in the next T line.

Output Format:

[Output]

Given the start coordinate and end coordinate, ask each square that passes through a maximum of one time, from the start coordinate to the end Coordinate

Total number of cases.

Input and Output sample Input example #1:
2 2 11 1 2 21 2
Output sample #1:
1
 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 using namespace std; 6 int bgx,bgy,edx,edy; 7 int n,m,t; 8 int xx[5]={-1,+1,0,0}; 9 int yy[5]={0,0,-1,+1};10 int map[50][50];11 int ans=0;12 int vis[50][50];13 void dfs(int x,int y)14 {15     if(x==edx&&y==edy)16     {17         ans++;18         return ;19     }20     for(int i=0;i<4;i++)21     {22         int wx=x+xx[i];23         int wy=y+yy[i];24         if(vis[wx][wy]==0&&map[wx][wy]!=1&&wx>=1&&wx<=n&&wy>=1&&wy<=m)25         {26             vis[wx][wy]=1;27             dfs(wx,wy);28             vis[wx][wy]=0;29         }30     }31     32 }33 int main()34 {35     36     scanf("%d%d%d%d%d%d%d",&n,&m,&t,&bgx,&bgy,&edx,&edy);37     for(int i=1;i<=t;i++)38     {39         int x,y;40         scanf("%d%d",&x,&y);41         map[x][y]=1;42     }43     vis[bgx][bgy]=1;44     dfs(bgx,bgy);45     printf("%d",ans);46     return 0;47 }

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.