Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
1,849 views

in Online Assessments by Expert (108,690 points) | 1,849 views

2 Answers

0 like 0 dislike
 #include <bits/stdc++.h>

using namespace std;
typedef long long int ll ; 
ll dp[500][5] ; 
ll n ; 

int main() {
    
    cin>>n ; 
    
    
    //2......right..
    //3.....left...
    //1.................full
    
    dp[1][1] = 0 ; 
    dp[1][2] = 0 ; 
    dp[1][3] = 0 ; 
    dp[2][1] = 3 ; 
    dp[2][2] = 1 ; 
    dp[2][3] = 1 ; 
    
  
    
    
    ll i = 3 ; 
    while(i<=n){
        
        dp[i][1] = 3*dp[i-2][1] + dp[i-2][2] + dp[i-2][3] ; 
        dp[i][2] = dp[i-2][1] + dp[i-2][2] ; 
        dp[i][3] = dp[i-2][1] + dp[i-2][3] ; 
        
        i++;
    }
    
    cout<<dp[n][1] ; 
    return 0 ; 
}
by Expert (108,690 points)
0 like 0 dislike

Image of Question : 

by Expert (108,690 points)

Get best answers to any doubt/query/question related to programming , jobs, gate, internships and tech-companies. Feel free to ask a question and you will receive the best advice/suggestion related to anything you ask about software-engineering , development and programming problems .