• 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 }
  • 相关阅读:
    HashMap源码分析
    静态代理和装饰模式的区别
    自动内存管理
    ReentrantReadWriteLock
    ReentranLock
    对象的内存布局
    对象的创建
    [P2495][SDOI2011]消耗战——虚树
    [HDU2966]In case of failure——KD树
    [Gym-101158J]Coverthe Polygon with Your Disk——梯度下降,模拟退火
  • 原文地址:https://www.cnblogs.com/zwfymqz/p/6604293.html
Copyright © 2020-2023  润新知