70分求助
查看原帖
70分求助
378976
Komeji_Irich1917楼主2020/10/28 22:08

rt,#2,#7,#8错了

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[10][10]={0,0,0,0,0,0,0,0,0,0};
int sx,sy,fx,fy,t,n,m,sum=0;
bool swg(int _,int __)
{
	if(a[_][__]>=1)
	{
		return 0;
	}
	if(_>n||_<1)
	{
		return 0;
	}
	if(__>m||__<1)
	{
		return 0; 
	}
	return 1;
}
void dfs(int x,int y)
{
	if(x==fx&&y==fy)
	{
		sum++;
		return;
	}
	int tmpx,tmpy;
	tmpx=x-1;
	tmpy=y;
	if(swg(tmpx,tmpy))
	{
		a[tmpx][tmpy]+=1;
		dfs(tmpx,tmpy);
		a[tmpx][tmpy]=0;
	}
	tmpx=x+1;
	tmpy=y;
	if(swg(tmpx,tmpy))
	{
		a[tmpx][tmpy]+=1;
		dfs(tmpx,tmpy);
		a[tmpx][tmpy]=0;
	}
	tmpx=x;
	tmpy=y-1;
	if(swg(tmpx,tmpy))
	{
		a[tmpx][tmpy]+=1;
		dfs(tmpx,tmpy);
		a[tmpx][tmpy]=0;
	}
	tmpx=x;
	tmpy=y+1;
	if(swg(tmpx,tmpy))
	{
		a[tmpx][tmpy]+=1;
		dfs(tmpx,tmpy);
		a[tmpx][tmpy]=0;
	}
	return;
}
int main()
{
	scanf("%d%d%d%d%d%d%d",&n,&m,&t,&sx,&sy,&fx,&fy);
	int tx,ty;
	for(int i=1;i<=t;i++)
	{
		scanf("%d%d",&tx,&ty);
		a[tx][ty]=114514;
	} 
	dfs(sx,sy);
	printf("%d",sum);
	return 0; 
}

2020/10/28 22:08
加载中...