MBEEWALK - Bee Walk - SPOJ Solution C++

  Problem Link : MBEEWALK 


👉 Hint : Use unordered map

 


✅ C++ Solution :

 
#include<bits/stdc++.h>
using namespace std;

#define ll long long int

ll dp[500][500][20];;

ll func(int i,int j,int n,int si,int sj)
{
	if(dp[i][j][n]!=-1)
		return dp[i][j][n];
	if(n==0)
	{
		if(i==si && j==sj)
			return 1;
		return 0;
	}
	dp[i][j][n]=func(i-2,j,n-1,si,sj)+func(i+2,j,n-1,si,sj)+func(i-1,j+2,n-1,si,sj)+func(i+1,j+2,n-1,si,sj)+func(i-1,j-2,n-1,si,sj)+func(i+1,j-2,n-1,si,sj);
	return dp[i][j][n];
}

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		memset(dp,-1,sizeof(dp));
		int n;
		cin>>n;
		int s=200;
		cout<<func(200,200,n,200,200)<<endl;

	}
}

 

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!!