2021ACM Club Reserve Camp Individual Training Game 12th Question A: Horse blocking the river pawn

Question A: The horse blocked the river.
Time limit: 1 Sec Memory limit: 128 MB

Title Description
There is a pawn crossing the river at point A on the chessboard and needs to go to the target point B. The rules of pawn walking: you 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 this horse is located and all the points that can be reached by jumping are called the opponent's horse's control points. Therefore it is called the "horse crossing the river pawn".
The chessboard is represented by coordinates, point A (0, 0), point B (n, m) (n, m are integers not exceeding 20), and the position coordinates of the horse must be given. Now you are required to calculate the number of paths that the pawn can take from point A to point B. Assuming that the position of the horse is fixed, it is not that the pawn walks one step at a time.

Enter
four data in one row, representing the coordinates of point B and the coordinates of horses. (Ensure that all data have solutions)
Output
a data, indicating the number of all paths.
Sample input Copy
6 6 3 3
Sample output Copy
6

Principle a [i] [j] = a [i-1] [j] + a [i] [j-1];

#include<bits/stdc++.h>
int cnt=0;
using namespace std;
typedef struct stu{
    
    
    int x,j;
}sss;
int cmp(int a,int b)
{
    
    
    return a>b;
}
typedef long long ll;
const int maxn=1e3+199;
 
ll a[100][130];
int k,nn;
int sum=0;
 
int main(){
    
    
 
 int x,y,x1,y1;
 cin>>x>>y>>x1>>y1;
 memset(a,sizeof(a),0);
 a[1][1]=1;
 x1++;y1++;
 x++;y++;
 for(int i=1;i<=x;i++)
 {
    
    
     for(int j=1;j<=y;j++)
     {
    
    
         if((abs(i-x1)==1&&abs(j-y1)==2)||(abs(i-x1)==2&&abs(j-y1)==1)||(i==x1&&j==y1))
            a[i][j]=0;
         else
            a[i][j]+=a[i-1][j]+a[i][j-1];
     }
 }
 cout<<a[x][y];
    return 0;
}

Guess you like

Origin blog.csdn.net/qq_52172364/article/details/113093347
Recommended