P1443求解
  • 板块灌水区
  • 楼主zhangshuhao123
  • 当前回复2
  • 已保存回复2
  • 发布时间2021/4/11 17:16
  • 上次更新2023/11/5 00:41:01
查看原帖
P1443求解
481203
zhangshuhao123楼主2021/4/11 17:16

程序哪里错了,老是30分,求大佬们帮助

#include<bits/stdc++.h>
using namespace std;
int n,m,t,sx,sy,fx,fy,mapp[7][7],total=0,mop[7][7];
int x[5]={0,0,0,1,-1};
int y[5]={0,1,-1,0,0};
//0障碍 1走过 2空 
void qk()
{
	for(int i=1;i<7;i++)
		for(int j=1;j<7;j++)
			if(mapp[i][j]==1)
				mapp[i][j]=2;
}
void dfs(int k)
{
    if(sx==fx&&sy==fy)
    {
        total++;
    }
    else
    {
        for(int i=1;i<=4;i++)
            if(sx+x[i]!=0&&sx+x[i]!=n&&sy+y[i]!=0&&sy+y[i]!=m&&!mop[sx+x[i]][sy+y[i]])
            {
                mop[sx][sy]=true;sx=sx+x[i];sy=sy+y[i];
                dfs(k+1);
                sx=sx-x[i];sy=sy-y[i];mop[sx][sy]=false;
            }
    }
}
int main()
{
	int a,b;
	cin>>n>>m>>t;
	cin>>sx>>sy>>fx>>fy;
	for(int i=0;i<t;i++)
	{
		cin>>a>>b;
		mapp[a][b]=0;
	}
	qk();
	dfs(0);
	cout<<total;
}
2021/4/11 17:16
加载中...