感觉思路没问题,但样例都过不了
查看原帖
感觉思路没问题,但样例都过不了
325959
乔奈楼主2020/8/30 11:28
#include<stdio.h>
int f (int i,int j,int x,int y)
{
	if(i<0||j<0)//走出棋盘 
		return 0;
	if(i==0&&j==0)	终点 
		return 1;
	if (i==x-2||i==x+2)
	{
		if(j==y-1||j==y+1)//马的攻击位置 
		return 0;
	} 
	else if (i==x-1||i==x+1)//攻击位置 
	{
		if(j==y+2||j==y-2)
		return 0;
	} 
	else if(i==x&&j==y)//马的位置 
		return 0;
	else return f(i-1,j,x,y)+f(i,j-1,x,y);	 
}
//本题倒着走 从终点回到起点

int main()
{
	int  bx,by,cx,cy;
	scanf("%d%d%d%d",&bx,&by,&cx,&cy);
	int sum=0;
	sum=f(bx,by,cx,cy);
	printf("%d",sum);
	return 0;
}
2020/8/30 11:28
加载中...