➤ Problem Link : 166E. Tetrahedron
✅ C++ Solution :
#include<bits/stdc++.h> using namespace std; #define ll long long int #define m 1000000007 int main() { ll n; cin>>n; ll dp[4]; dp[3]=0; dp[0]=1; dp[1]=1; dp[2]=1; ll temp1,temp2,temp3,temp4; for(int i=2;i<=n;i++) { temp1=(dp[1]+(dp[2]+dp[3])%m)%m; temp2=(dp[0]+(dp[2]+dp[3])%m)%m; temp3=(dp[0]+(dp[1]+dp[3])%m)%m; temp4=(dp[0]+(dp[2]+dp[1])%m)%m; dp[0]=temp1; dp[1]=temp2; dp[2]=temp3; dp[3]=temp4; } cout<<dp[3]; }
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!!