➤ Problem Link : M3TILE
👉 Hint : edit please
✅ C++ Solution :
#include<bits/stdc++.h>
using namespace std;
int main()
{
while(1)
{
int n;
cin>>n;
if(n==-1)
break;
long long int dp[n+2][n+2];
memset(dp,0,sizeof(dp));
dp[0][0]=1;
dp[1][0]=dp[0][1]=1;
dp[1][1]=0;
dp[1][2]=0;
dp[2][1]=0;
dp[2][2]=3;
dp[2][3]=4;
for(int i=3;i<=n;i++)
{
for(int j=i-1;j<=i+1&&j<=n;j++)
{
if(i==j)
dp[i][j]=dp[i-1][j-2]+dp[i-2][j-1]+dp[i-2][j-2];
else if(i>j)
dp[i][j]=dp[i-2][j-2]+dp[i-1][j];
else if(i<j)
dp[i][j]=dp[i-2][j-2]+dp[i][j-1];
}
}
cout<<dp[n][n]<<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!!
