Luogu p1002 Crossing the River

Coordinate type dp ten thousand year motif

Generally, it is pushed from the initial start of f

the same way

Topic description

There is a river crossing pawn at point A on the chessboard and needs to go to the target point B. The rules of pawn walking: it can go down or to the right. At the same time, there is an opponent's horse at point C on the chessboard. The point where the horse is located and all the points that can be reached by jumping one step are called the control points of the opponent's horse. Therefore, it is called "horse crossing the river".

The chessboard is represented by coordinates, point A (0, 0), point B (n, m) (n, m is an integer not exceeding 20), and the position coordinates of the horse also need to be given.

Now you are asked to count the number of paths the pawn can take from point A to point B, assuming that the position of the horse is fixed, not that the pawn takes a step and the horse takes a step.

Input and output format

Input format:

 

A row of four data, respectively representing the coordinates of point B and the coordinates of the horse.

 

Output format:

 

A data representing the number of all paths.

 

Input and output example

Input Example #1:  Copy
6 6 3 3
Output Sample #1:  Copy
6

illustrate

The results can be huge!

This description means

longlong not less

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 #include<algorithm>
 5 using namespace std;
 6 long long g[30][30],f[30][30],n,m,k,l,a,b,c,x,y;
 7 bool check(int xx,int yy)
 8 {
 9     if(xx==x&&yy==y)
10     return 0;
11     if((xx+2==x||xx-2==x)&&(yy+1==y||yy-1==y))
12     return 0;
13     if((yy+2==y||yy-2==y)&&(xx+1==x||xx-1==x))
14     return 0;
15     return 1;
16 }
17 int main()
18 {
19     cin>>n>>m>>x>>y;
20     memset(f,0,sizeof(f));
21     f[0][0]=1;
22     for(int i=0;i<=n;i++)
23     for(int j=0;j<=m;j++)
24     {
25         if(!check(i,j))
26         continue;
27         if(i>0)
28         f[i][j]=f[i-1][j];
29         if(j>0)
30         f[i][j]+=f[i][j-1];
31     }
32     cout<<f[n][m]<<endl;
33     return 0;
34 }

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326832254&siteId=291194637