codevs1219 骑士游历

来源:互联网 发布:杀出矩阵:起源 编辑:程序博客网 时间:2024/03/29 22:46

题目描述 Description

设有一个n*m的棋盘(2≤n≤50,2m≤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

最近很颓……在做sb题

因为没开long long还wa了一次

话说codevs的天梯还真是有趣啊……我都到黄金组了

#include<cstdio>#define LL long longconst int mx[4]={1,2,2,1};const int my[4]={2,1,-1,-2};LL f[60][60];int n,m,x1,x2,y1,y2;int main(){scanf("%d%d",&n,&m);scanf("%d%d%d%d",&x1,&y1,&x2,&y2);f[x1][y1]=1;for (int i=1;i<=n;i++)  for (int j=1;j<=m;j++)for (int k=0;k<4;k++)  {  int nx=i+mx[k];  int ny=j+my[k];  if (nx<1||nx>n||ny<1||ny>m)continue;  f[nx][ny]+=f[i][j];  }printf("%lld\n",f[x2][y2]);}

0 0
原创粉丝点击