【CODEVS1219】骑士游历

Description

设有一个n*m的棋盘(2≤n≤50,2≤m≤50),如下图,在棋盘上有一个中国象棋马。

规定:

1)马只能走日字

2)马只能向右跳

问给定起点x1,y1和终点x2,y2,求出马从x1,y1出发到x2,y2的合法路径条数。

Input

第一行2个整数n和m

第二行4个整数x1,y1,x2,y2

Output

输出方案数

Sample Input

30 30

1 15 3 15

Sample Output

2

HINT

2<=n,m<=50

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
long long a[100][100];
int main(){
    memset(a,0,sizeof(a));
    int n,m,x1,x2,y1,y2;
    scanf("%d%d%d%d%d%d",&n,&m,&x1,&y1,&x2,&y2);
    a[x1][y1]=1;
    for (int i=x1+1;i<=n;i++)
        for (int j=1;j<=m;j++)
        { a[i][j]=a[i-1][j+2];
        if (j-2>=0) a[i][j]+=a[i-1][j-2];
        if (i-2>=0) a[i][j]+=a[i-2][j+1]+a[i-2][j-1];
        }
    printf("%lld",a[x2][y2]);
    return 0;
}
原文地址:https://www.cnblogs.com/liumengyue/p/5137299.html