题目描述 Description
设有一个n*m的棋盘(2≤n≤50,2≤m≤50),如下图,在棋盘上有一个中国象棋马。
规定:
1)马只能走日字
2)马只能向右跳
问给定起点x1,y1和终点x2,y2,求出马从x1,y1出发到x2,y2的合法路径条数。
输入描述 Input Description
第一行2个整数n和m
第二行4个整数x1,y1,x2,y2
输出描述 Output Description
输出方案数
样例输入 Sample Input
30 30
1 15 3 15
样例输出 Sample Output
2
数据范围及提示 Data Size & Hint
2<=n,m<=50
#include<iostream>
using namespace std;
int main()
{
int n,m,x1,y1,x2,y2;
long long f[51][51]={0};
cin>>n>>m;
cin>>x1>>y1>>x2>>y2;
f[x1][y2]=1;
for (int i=x1+1;i<=x2;i++)
for (int j=1;j<=n;j++)
{
if (j+2<=n)
f[i][j]+=f[i-1][j+2];
if (j-2>=0)
f[i][j]+=f[i-1][j-2];
if ((j+1<=n) && (i-2>=x1))
f[i][j]+=f[i-2][j+1];
if ((j-1>=0) && (i-2>=x1))
f[i][j]+=f[i-2][j-1];
}
cout<<f[x2][y2];
return 0;
}