蒟蒻水红dfs又又又写炸了,悬2关求助
查看原帖
蒟蒻水红dfs又又又写炸了,悬2关求助
765461
zhangmingsheng3521楼主2023/8/22 07:19

rt.思路是用一个数组存储每个点能/不能走 然后这是我神奇的评测记录 源代码放在下面:

#include"bits/stdc++.h"
using namespace std;
int tu[30][30];
int x,y,hx,hy,ans=0;
void dfs(int a,int b)
{
	if ((a==x)&&(b==y))
	{
		ans++;
		return;
	}
	if (tu[a][b]==0)
	{
		return;
	}
	if (a<x) 
	{
		dfs((a+1),b);
	}
	if (b<y)
	{
		dfs(a,(b+1));
	}
}
int main()
{
	scanf("%d%d%d%d",&x,&y,&hx,&hy);
	x++;
	y++;
	for (int i=0;i<=(x+1);i++)
	{
		for (int j=0;j<=(y+1);j++)
		{
		   tu[i][j]=1;
	    }
	}
	tu[hx+1][hy+1]=0;
	tu[hx+3][hy+2]=0;
	tu[hx+2][hy+3]=0;
	tu[hx-1][hy]=0;
	tu[hx][hy-1]=0;
	tu[hx][hy+3]=0;
	tu[hx-1][hy+2]=0;
	tu[hx+3][hy]=0;
	tu[hx+2][hy-1]=0;
	dfs(1,1);
	printf("%d",ans);
	return 0;
}
2023/8/22 07:19
加载中...