题目描述
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> #include<algorithm> using namespace std; long long f[55][55]={0}; int main() { //读入 int n,m,x1,y1,x2,y2; cin>>n>>m; cin>>x1>>y1>>x2>>y2; f[x1][y1]=1; //DP for(int a=x1+1;a<=x2;a++) { for(int b=1;b<=m;b++) { f[a][b]=f[a][b]+f[a-1][b-2]+f[a-2][b-1]+f[a-1][b+2]+f[a-2][b+1]; } } cout<<f[x2][y2]; return 0; }