1,4 re 求助
查看原帖
1,4 re 求助
979891
ccioc楼主2023/11/19 16:31
#include<stdio.h>
#define N 23
typedef struct{
	int x,y;
}position;
position horse;
position b;
long long s[N][N]={0},dp[N][N]={0};
int dx[2]={-1,0},dy[2]={0,-1};
int isOK(int x,int y){
	if(x>=0&&x<=b.x&&y>=0&&y<=b.y&&!s[x][y])
		return 1;
	return 0;
}
int main(){
	scanf("%d %d %d %d",&b.x,&b.y,&horse.x,&horse.y);
	int i,j,sum=0;
	int x=horse.x;
	int y=horse.y;
	s[x][y]=1;
	s[x-1][y+2]=1;
	s[x-2][y+1]=1;
	s[x-1][y-2]=1;
	s[x-2][y-1]=1;
	s[x+1][y+2]=1;
	s[x+2][y+1]=1;
	s[x+2][y-1]=1;
	s[x+1][y-2]=1; 
	dp[0][0]=1;
	int nx,ny,k;
	for(i=0;i<=b.x;i++){
		for(j=0;j<=b.y;j++){
			if(i==0&&j==0)	continue;
			if(i>=0&&i<=b.x&&j>=0&&j<=b.y&&!s[i][j]){
				for(k=0;k<2;k++){
					nx=i+dx[k];
					ny=j+dy[k];
					if(isOK(nx,ny)){
						dp[i][j]+=dp[nx][ny];
					}
				}
			}
			
		}
	}
	printf("%lld",dp[b.x][b.y]);
}
2023/11/19 16:31
加载中...