详细题解
2025-08-06 14:17:25
发布于:北京
1阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
#define V vector
#define all0(x) (x).begin(),(x).end()
#define all1(x) (x).begin()+1,(x).end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
typedef long long LL;
typedef pair<int, int> pi;
typedef pair<LL, LL> pl;
const int N = 5 + 20;
const int INF = 0x3f3f3f3f;
const LL INFLL =0x3f3f3f3f3f3f3f3f;
int dx[] = {-2 , -1 , 1 , 2 , 2 , 1 , -1 , -2};//马走日的横坐标
int dy[] = {1 , 2 , 2 , 1 , -1 , -2 , -2 , -1};//马走日的纵坐标
LL dp[N][N]; // dp [i][j] 表示在当前ij的坐标下,最多的路径条数.
int pos[N][N];//判断是否属于马走日的坐标点.
void so() {
int n , m , sx , sy;
cin >> n >> m >> sx >> sy; //输入初始数据
pos[sx][sy] = 1; //标记马的坐标
for(int i = 0 ; i < 8 ; i++) pos[sx + dx[i]][sy + dy[i]] = 1; //标记马走日的坐标,都是不能走的
dp[0][0] = 1;//初始化坐标原点有一条路.
for(int i = 0 ; i <= n ; i++ ){
for(int j = 0 ; j <= m ; j++){
if(!pos[i][j]){//如果这条路不是马可以达到的坐标
dp[i][j] += dp[i][j - 1] + dp[i - 1][j]; //当前的最多路径数,可以从上面和左边分别转移过来.
}
}
}
cout <<dp[n][m] <<endl;//输出答案
}
int main() {
IOS
int tt=1;
// cin >> tt;
while (tt--)
so();
}
这里空空如也
有帮助,赞一个