全re求助
查看原帖
全re求助
1288805
hnyn楼主2024/5/3 21:08
#include <iostream>
#include <cstdio>
#include<cstring>
using namespace std;
const int N = 30;
int f[N][N];
int dx[8] = {2, 1, -1, -2, -2, -1, 1, 2}, dy[8] = {1, 2, 2, 1, -1, -2, -2, -1};
int cal(int x, int y) {
    if(f[x][y]!=0)return f[x][y];
    return f[x][y] = cal(x - 1, y) + cal(x, y - 1);
}
int main() {
    int x1, y1, x2, y2;
    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
    x1+=2,y1+=2,x2+=2,y2+=2; 
    f[2][2]=1;
    for (int i = 0; i < 8; i++) {
        int x = x2 + dx[i], y = y2 + dy[i];
            f[x][y] = 0; // 标记马的位置及其能走到的位置的方案数为 0
    }
    long long answer = cal(x1, y1);
    printf("%lld", answer);
    return 0;
}//记住马跳跃时有横坐标减2,纵坐标减2,故起始坐标要加2防止数组越界
2024/5/3 21:08
加载中...