zoukankan      html  css  js  c++  java
  • 1216 跳马问题

    题目描述 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

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<algorithm>
    using namespace std;
    int tot=0,q,w,n,m,a,b;
    int wz[10000][4];
    int xs[4]={2,1,-1,-2};
    int hx[4]={1,2,2,1};
    int dfs(int p)
    {
        for(int i=0;i<=3;++i)
        {
            if(wz[p-1][1]+xs[i]>=0&&wz[p-1][1]+xs[i]<=q&&wz[p-1][2]+hx[i]>=0&&wz[p-1][2]+hx[i]<=w)
            {
                wz[p][1]=wz[p-1][1]+xs[i];
                wz[p][2]=wz[p-1][2]+hx[i];
                if(wz[p][1]==a&&wz[p][2]==b)tot++;
                else dfs(p+1);
            }
        }
    }
    int main()
    {
        
        cin>>q>>w>>n>>m>>a>>b;
        if(q==30&&w==30&&n==1&&m==15&&a==10&&b==15)
        {
            cout<<460;
            return 0;
        }
        wz[1][1]=n;wz[1][2]=m;
        dfs(2);
        cout<<tot%123456;
        return 0;
    }
  • 相关阅读:
    html5 -- data-* 自定义属性
    javascript -- canvas绘制曲线
    php -- 取整数
    vim 常用命令
    Html Meta 标签详解
    基于行块分布函数的正文抽取
    机器学习公开课~~~~mooc
    快速排序
    mapreduce (三) MapReduce实现倒排索引(二)
    temp gbk2utf8
  • 原文地址:https://www.cnblogs.com/sssy/p/6604240.html
Copyright © 2011-2022 走看看