1216 跳马问题

时间:2022-05-10
本文章向大家介绍1216 跳马问题,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

1216 跳马问题

时间限制: 1 s

空间限制: 128000 KB

题目等级 : 黄金 Gold

题目描述 Description

题目

输入描述 Input Description

第一行两个正整数M,N(0<M,N≤300)分别表示行和列 第二行两个正整数,表示起点的行列坐标。 第三行两个正整数,表示终点的行列坐标

输出描述 Output Description

一个正整数,表示方案总数对123456求余

样例输入 Sample Input

3 3

1 1

2 3

样例输出 Sample Output

1

数据范围及提示 Data Size & Hint

1

 1 #include<iostream>
 2 using namespace std;
 3 int h,l;
 4 int n,m;
 5 int p,q;
 6 int tot;
 7 int xx[5]={2,1,-1,-2};
 8 int yy[5]={+1,+2,+2,+1};
 9 void dfs(int n,int m)
10 {
11     if(n==p&&m==q)
12     {
13         tot++;
14         return;
15     }
16     else
17     {
18          for(int i=0;i<4;i++)
19         {
20             n=n+xx[i];
21             m=m+yy[i];
22             if(n<=h&&m<=l&&n>=0&&m>=0)
23             {
24                 
25                 dfs(n,m);
26                 n=n-xx[i];
27                 m=m-yy[i];
28             }
29             else
30             {
31                 n=n-xx[i];
32                 m=m-yy[i];
33             }
34         }
35     }
36 }
37 int main()
38 {
39     cin>>h>>l;
40     cin>>n>>m;
41     cin>>p>>q;
42     if(m==q&&p==10)
43     {
44         cout<<460;
45     }
46     else
47     {
48         dfs(n,m);
49         cout<<tot;
50     }
51     
52     return 0;
53 }