码迷,mamicode.com
首页 > 其他好文 > 详细

1216 跳马问题

时间:2017-03-23 14:15:44      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:ace   blog   题目   inline   范围   panel   src   output   out   

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 }

 

1216 跳马问题

标签:ace   blog   题目   inline   范围   panel   src   output   out   

原文地址:http://www.cnblogs.com/zwfymqz/p/6604293.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!