神犇们,60
  • 板块灌水区
  • 楼主Innate_Joker
  • 当前回复2
  • 已保存回复2
  • 发布时间2024/6/15 10:42
  • 上次更新2024/6/15 13:54:16
查看原帖
神犇们,60
1086443
Innate_Joker楼主2024/6/15 10:42

本人不会记忆化,发帖纯粹学习

#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);
			}
		}
	}
}

题目传送门

2024/6/15 10:42
加载中...