【NOIP1997】【codevs1219】骑士游历

problem

solution

codes

//bugs:行列弄反(x,y是坐标轴...)+longlong
#include<iostream>
using namespace std;
typedef long long LL;
LL n, m, x1, y1, x2, y2, f[55][55];
int main(){
    cin>>n>>m>>x1>>y1>>x2>>y2;
    f[x1][y1] = 1;
    for(int i = x1+1; i <= x2; i++)//避免覆盖掉x1,y1时候的1种方案
        for(int j = 1; j <= n; j++)//因为日字,所以要全
            f[i][j] = f[i-1][j-2]+f[i-1][j+2]+f[i-2][j-1]+f[i-2][j+1];
    cout<<f[x2][y2]<<"
";
    return 0;
}
//行列式反的,,,
#include<iostream>
using namespace std;
typedef long long LL;
LL n, m, x1, y1, x2, y2, f[55][55];
int main(){
    cin>>n>>m>>x1>>y1>>x2>>y2;
    f[y1][x1] = 1;
    //转移的时候按照列每层去取(因为只能往右走)
    for(int i = x1; i <= x2; i++){//枚举y
        for(int j = 1; j <= m; j++){//枚举x
            //之前的状态无法到达那么当前状态也无法到达
            if(!f[j][i])continue;
            //刷表状态转移
            f[j+1][i+2] += f[j][i];
            f[j-1][i+2] += f[j][i];
            f[j+2][i+1] += f[j][i];
            f[j-2][i+1] += f[j][i];
        }
    }
    cout<<f[y2][x2]<<"
";
    return 0;
}
原文地址:https://www.cnblogs.com/gwj1314/p/9444772.html