请问大佬们这样子为啥子就跑不出来呢》-《
查看原帖
请问大佬们这样子为啥子就跑不出来呢》-《
1147148
xiaoxiaoweizainuli楼主2024/1/11 22:20
#include<stdio.h>
int j = 0;
dfs(int a,int b, int c,int d,int arr[21][21],int x,int y)
{
	if (0 <= x && x <= 20 && 0 <= y && y <= 20)
	{
		if (x == a && y == b)
		{
			j++;
			return  ;
		}
		if (x + 1 <= 20 && ((x+1 - c) *(x+1 - c) + (y - d) *(y - d)) != 5 && arr[x + 1][y] == 0);
		{
			if (x + 1 == c && y == d)
			{
				return;
			}
			arr[x+1][y] = 1;
			dfs(a, b, c, d, arr, x+1, y);
			arr[x+1][y] = 0;
		}
		if (y +1<= 20 && ((x - c) *(x - c) + (y+1 - d) *(y+1 - d)) != 5 &&arr[x][y+1] == 0);
		{
			if (x == c && y + 1 == d)
			{
				return;
			}
			arr[x][y+1] = 1;
			dfs(a, b, c, d, arr, x, y+1);
			arr[x ][y+1] = 0;
		}
	}
}
int main()
{
	int arr[21][21];
	int x = 0;
	int y = 0;//初始坐标
	int a;
	int b;
	int c;
	int d;
	int i;
	int k;
	for (i = 0; i <= 20; i++)
	{
		for (k = 0; k <= 20; k++)
		{
			arr[i][k] = 0;
		}
	}
	scanf("%d", &a);
	scanf("%d", &b);//终点坐标
	scanf("%d", &c);
	scanf("%d", &d);//马的坐标
	dfs(a, b, c, d, arr, x, y);
	printf("%d", j);
}
2024/1/11 22:20
加载中...