https://vijos.org/p/1121
实际上这题其实是递推。。
到一个点的路径条数为它左边和上面的点的路径和
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ms(i,j) memset(i, j, sizeof(i));
#define pa2(a,x,y) for (int i=0;i<=x;i++){ for (int j=0;j<=y;j++) if (a[i][j]==-100000000) printf("X "); else printf("%d ", a[i][j]); putchar('\n');}
using namespace std;
const int maxm = 15 + 5, maxn = 15 + 5, INF = 100000000;
const int dx[9] = {0,2,2 ,1 ,-1,-2,-2,-1,1};
const int dy[9] = {0,1,-1,-2,-2,-1,1 ,2 ,2};
int n,m,x,y;
int f[maxn][maxm];
int main ()
{
scanf("%d%d%d%d", &n, &m, &x, &y);
ms(f,0);
f[0][0] = 1;
for (int i=0;i<9;i++)
{
if (x+dx[i]>=0&&x+dx[i]<=n&&y+dy[i]>=0&&y+dy[i]<=m)
{
f[x+dx[i]][y+dy[i]] = -INF;
}
}
for (int i=0;i<=m;i++)
{
if (f[0][i]!=-INF) f[0][i] = 1; else break;
}
for (int i=0;i<=n;i++)
{
if (f[i][0]!=-INF) f[i][0] = 1; else break;
}
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
{
if (f[i][j]!=-INF)
{
if (f[i-1][j]!=-INF) f[i][j] += f[i-1][j];
if (f[i][j-1]!=-INF) f[i][j] += f[i][j-1];
}
}
printf("%d\n", f[n][m]);
return 0;
}