​传送门​​​ 思路:搜索tle了,只能dp了。
dp[i][j] = dp[i][j-1]+dp[i-1][j];
对于 点(i,j),只有(i,j-1) 和 (i-1,j)这两种选择,那么可以推出状态转移方程
先定义dp[0][0] = 1;
dp[i][j] =dp[i - 1][j] + dp[i][j - 1];
但如果这样的话,以0,0为起点会出现点被覆盖的情况,所以我们做一下小改动
然后就有
dp[i][j] = max(dp[i][j],dp[i - 1][j] + dp[i][j - 1]);
如果该点是马的覆盖点的话,它必然有0条路线。

if(vis[i][j])
dp[i][j] = 0;
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<queue>
#include<cmath>
#include<cctype>
#include<stack>
#include<map>
#include<string>
#include<cstdlib>
#define ll long long
using namespace std;
const ll maxn = 1e6 + 5;
const ll minn = 1e9 + 5;
const ll mod = 1000000007;
const int INF = 0x3f3f3f3f;
const long long LIMIT = 4294967295LL;
vector<int>v[maxn];
ll dp[50][50];
vector<int>G[maxn];
bool row[maxn], col[maxn];
bool flag = 0;
int vis[50][50];
queue<int>q;
int main() {
ios::sync_with_stdio(false);
int bx, by, cx, cy;
cin >> bx >> by >> cx >> cy;
vis[cx][cy] = 1;
vis[cx - 2][cy - 1] = 1;
vis[cx - 1][cy - 2] = 1;
vis[cx + 1][cy + 2] = 1;
vis[cx + 2][cy + 1] = 1;
vis[cx - 1][cy + 2] = 1;
vis[cx + 1][cy - 2] = 1;
vis[cx - 2][cy + 1] = 1;
vis[cx + 2][cy - 1] = 1;
dp[0][0] = 1;
for(int i = 0; i <= bx; i++)
for(int j = 0; j <= by; j++) {
dp[i][j] = max(dp[i][j],dp[i - 1][j] + dp[i][j - 1]);
if(vis[i][j])
dp[i][j] = 0;
}
cout << dp[bx][by] << endl;
return 0;
}