本人不会记忆化,发帖纯粹学习
#include<cstdio>
using namespace std;
int sh[24][24];
void search(int,int);
int n,m,man,mam,total;
int dx[2] {1,0},dy[2] {0,1};
int gx[8] {-2,-1,1,2,2,1,-1,-2},gy[8] {1,2,2,1,-1,-2,-2,-1};
int main() {
scanf("%d%d%d%d",&n,&m,&man,&mam);
sh[man][mam]=1;
for(int i=0; i<8; i++) {
sh[man+gx[i]][mam+gy[i]]=1;
}
search(0,0);
printf("%d",total);
return 0;
}
void search(int x,int y) {
if(x==n&&y==m) {
++total;
return;
} else {
for(int i=0; i<2; i++) {
int hx=x+dx[i];
int hy=y+dy[i];
if(hx>=0 and hy>=0 and hx<=n and hy<=m and !sh[hx][hy]) {
search(hx,hy);
}
}
}
}