ALCATRAZ3 - THE HONEYCOMB MAZE - SPOJ Solution C++

  Problem Link : ALCATRAZ3 


👉 Hint : edit please

 


✅ C++ Solution :

 
#include<bits/stdc++.h>
using namespace std;
char arr[101][101];
bool visited[101][101];
int arr1[]={0,-1,1,0};
int arr2[]={1,0,0,-1};
int sx,sy,n,m,k;
bool dfs(int x,int y,int l)
{
	visited[x][y]=1;
	for(int i=0;i<4;i++)
	{
		int a=x+arr1[i];
		int b=y+arr2[i];
		if(a==sx && b==sy)
		{
			if(l>=k)
				return true;
			return false;
		}
		if(a<=n && a>=1 && b<=m && b>=1 && arr[a][b]!='*' && !visited[a][b] && dfs(a,b,l+1))
			return true;
			
 
	}
	visited[x][y]=0;
	return false;
 
}
 
int main()
{
	cin>>n>>m;
	cin>>k;
	cin>>sx>>sy;
	memset(visited,0,sizeof(visited));
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
			cin>>arr[i][j];
	}
	if(dfs(sx,sy,1))
		cout<<"YES";
	else
		cout<<"NO";
}

 

Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook. 

😇Happy Learning!!