题目描述 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
分类标签 Tags 点此展开
1 #include <algorithm> 2 #include <cstdio> 3 4 #define LL long long 5 6 using namespace std; 7 8 LL n,m,x1,y1,x2,y2; 9 LL f[55][55]; 10 11 int main() 12 { 13 scanf("%lld%lld",&n,&m); 14 scanf("%d%d%d%d",&x1,&y1,&x2,&y2); 15 f[x1][y1]=1; 16 for(int i=x1+1;i<=x2;i++) 17 for(int j=1;j<=m;j++) 18 f[i][j]=f[i-2][j-1]+f[i-2][j+1]+f[i-1][j-2]+f[i-1][j+2]; 19 printf("%lld",f[x2][y2]); 20 return 0; 21 }