The given problem is a pretty basic dynamic problem.It can be solved using counting principle and dynamic programming. But I am receiving incorrect answer for this approach which seems logically correct to me.It will be kind of you if you could help me out.
#include<bits/stdc++.h>
using namespace std;
int solve(int A) {
long long int mod=1e9+7;
int dp[A][3][4]={0};
for(int j=0;j<4;j++)
dp[0][0][j]=1;
for(int i=0;i<A;i++)
{
for(int j=0;j<3;j++)
{
for(int k=0;k<4;k++)
{
for(int p=0;p<4;p++)
{
if(p!=k)
{if(j>=1)
dp[i][j][k]+=dp[i][j-1][p];
dp[i][j][k]%=mod;
if(i>=1)
dp[i][j][k]+=dp[i-1][j][p];
dp[i][j][k]%=mod;
}
}
}
}
}
return (dp[A-1][2][0]+dp[A-1][2][1]+dp[A-1][2][2]+dp[A-1][2][3])%mod;
}
int main()
{
int a=2;
cout<<solve(2);
}