[NOIP2002 Popularization Group] Crossing the River Pawn

[NOIP2002 Popularization Group] Crossing the River Pawn

Question description

Kibanjo A A There is a river-crossing pawn at A and needs to go to the target B B B point. The rules for pawn walking: it can go down or to the right. At the same time on the chessboard C C There is an opponent's horse at point C. The point where the horse is located and all points reachable by one jump are called the control points of the opponent's horse. Therefore, it is called "horse blocking the river and pawns".

Chess box display, A A A ( 0 , 0 ) (0, 0) (0,0) B B B ( n , m ) (n, m) (n,m), the position coordinates of the horse also need to be given.

You are now asked to calculate the pawns A A A Point 力够到达 B B B The number of paths to the point. It is assumed that the position of the horse is fixed, and it does not mean that the pawn moves one step and the horse moves one step.

Input format

Four positive integers in a row, respectively representing B B B Point coordinates and horse coordinates.

Output format

An integer representing the number of all paths.

Example #1

Sample input #1

6 6 3 3

Sample output #1

6

hint

对于 100 % 100 \% 1 ≤ n , m ≤ 20 1 \le n , m \le 20 1n,m20, 0 ≤ 0 \le0 马的材标 ≤ 20 \le 20 20

[Source of the question]

NOIP 2002 Popularization Group Question 4

solution

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int fx[10] = {
    
    0,-2,-1, 1, 2, 2, 1,-1,-2};
int fy[10] = {
    
    0, 1, 2, 2, 1,-1,-2,-2,-1};
int bx,by,mx,my;
long long f[40][40];
bool s[40][40]; 
int main()
{
    
    
    scanf("%d%d%d%d",&bx,&by,&mx,&my);
    bx+=2; by+=2; mx+=2; my+=2;
    f[2][1]=1;
    s[mx][my]=1;
    for(int i=1; i<=8;i++)
		s[mx + fx[i]][my + fy[i]] = 1;
    for(int i=2;i<=bx;i++)
	{
    
    
        for(int j=2;j<=by;j++)
		{
    
    
            if(s[i][j])
				continue; 
            f[i][j]=f[i - 1][j]+f[i][j - 1];
        }
    }
    printf("%lld\n", f[bx][by]);
    return 0;
} 

Guess you like

Origin blog.csdn.net/DUXS11/article/details/134747212