【动态规划】CODE[VS] 1219 骑士游历 【Noip1997】

去下中国象棋

棋盘dp的水题,固定一边(x轴或y轴),一直按照规则(走日向右)累加过去
数据比较大,小心爆int,注意开long long就完了
//关于边界,根本没有必要,原因显然(赐给问我这个问题的狗儿子 QWQ)

代码

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;
typedef long long LL;

const int maxn = 101;

LL n,m;
LL x1,y1,x2,y2;
LL dp[maxn][maxn];

int main()
{
    scanf("%lld%lld",&n,&m);
    scanf("%lld%lld%lld%lld",&x1,&y1,&x2,&y2);
    dp[x1][y1] = 1;
    for(LL i = x1+1;i <= x2;i++)
        for(LL j = 1;j <= n;j++)
        {
            dp[i][j] = dp[i-1][j+2]+dp[i-1][j-2]+dp[i-2][j+1]+dp[i-2][j-1];
            //马走日字,每次有4种走法
        }
    printf("%lld\n",dp[x2][y2]);//输出到达终点一共有多少种走法
 return 0;
}

THE END

By Fograin

http://blog.csdn.net/loi_peacefuldog

    原文作者:骑士周游问题
    原文地址: https://blog.csdn.net/loi_peacefuldog/article/details/69372361
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞